Skip to content

gabrielcipriano/using-pool

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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"]
        // (...)
    }
}

About

An object pool library using modern Typescript for auto-recycling

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published