Skip to content

Latest commit

 

History

History
42 lines (31 loc) · 1007 Bytes

README.md

File metadata and controls

42 lines (31 loc) · 1007 Bytes

ManagedPool-sw

A tunable thread safe pool of objects with internally managed expiration.

Adding To Project

    dependencies: [
        .package(url: "https://github.com/neallester/ManagedPool-sw.git", .branch("master")),
    ],
    targets: [
        .target(
            dependencies: ["ManagedPool"]),
    ]

Usage

To create a pool with the default parameters:

class MyClass {
    func doSomething() {}
}

let pool = ManagedPool<MyClass>(capacity: 10) {
    return MyClass()
}

{
    let m = try pool.checkout()
    m.object.doSomething()
    pool.checkIn (m)
}

// Invalidate the pool before its variable goes out of scope (or is set to nil) or the
// memory used by the pool will never be collected

pool.invalidate()

See the ManagedPool.init() for all of the parameters which may be used to tune the behavior of the pool.