A tunable thread safe pool of objects with internally managed expiration.
dependencies: [
.package(url: "https://github.com/neallester/ManagedPool-sw.git", .branch("master")),
],
targets: [
.target(
dependencies: ["ManagedPool"]),
]
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.