using-pool
v1.1.1
Published
An object pool library using modern Typescript for auto-recycling
Downloads
2
Maintainers
Readme
using-pool
An object pool library using modern Typescript for auto-recycling.
It takes advatage of the using
keyword to recycle the object as soon as it leaves the scope.
Example:
import { Pool } from 'using-pool'
const userPool = new Pool(() => ({/** an object factory */}))
function doSomething() {
using user = userPool.get()
// do some work with the object
// (...)
} // as soon as it leaves the scope, `user` is recycled (comes back to the pool to be reused)
Installation
npm install using-pool
or
yarn add using-pool
pre requisites
- node version:
14
or later - typescript version:
5.2.0-beta
or later
You will also need to set your compilation target to "es2022"
or below, and configure your lib setting to either include "esnext"
or "esnext.disposable"
.
// tsconfig.json
{
"compilerOptions": {
"target": "es2022",
"lib": ["es2022", "esnext.disposable", "dom"]
// (...)
}
}