reswifq/pool
A generic object pool implementation for Swift that works on macOS and Linux.
π Getting Started
Import Pool into your project using Swift Package Manager:
import PackageDescription
let package = Package(
name: "YourProject",
products: [
.executable(name: "YourProject", targets: ["YourProject"])
],
dependencies: [
.package(url: "https://github.com/reswifq/pool.git", .upToNextMajor(from: "1.3.0"))
],
targets: [
.target(name: "YourProject", dependencies: ["Pool"])
]
)Create a pool of elements:
let pool = Pool(maxElementCount: 10) {
return "I am a pool element"
}Draw an element from the pool:
let element = try pool.draw()Do something with it:
print(element) // "I am a pool element"Put it back in the pool, so it can be reused:
pool.release(element)Optionally you can wait until it has been released:
pool.release(element) {
print("element has been released and it's ready to be drawn again")
}π§ Compatibility
This package has been tested on macOS and Ubuntu.
π License
Created by Valerio Mazzeo.
Copyright Β© 2017 VMLabs Limited. All rights reserved.
This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU Lesser General Public License for more details.
Package Metadata
Repository: reswifq/pool
Default branch: master
README: README.md