Skip to content

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

License

Notifications You must be signed in to change notification settings

neallester/ManagedPool-sw

Repository files navigation

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.

About

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

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages