A generic object pool implementation for Swift that works on macOS and Linux.
Import Pool into your project using Swift Package Manager:
import PackageDescription
let package = Package(
name: "YourProject",
targets: [],
dependencies: [
.Package(url: "https://github.com/reswifq/pool.git", majorVersion: 1)
]
)
let pool = Pool(maxElementCount: 10) {
return "I am a pool element"
}
let element = try pool.draw()
print(element) // "I am a pool element"
pool.release(element)
pool.release(element) {
print("element has been released and it's ready to be drawn again")
}
This package has been tested on macOS and Ubuntu.
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.