UNPKG

@smikhalevski/object-pool

Version:
32 lines (22 loc) 878 B
# object-pool [![build](https://github.com/smikhalevski/object-pool/actions/workflows/master.yml/badge.svg?branch=master&event=push)](https://github.com/smikhalevski/object-pool/actions/workflows/master.yml) [The tiny](https://bundlephobia.com/package/@smikhalevski/object-pool) and efficient object pool. This implementation was inspired by [deePool](https://github.com/getify/deePool) and is slightly faster than the original. ```shell npm install @smikhalevski/object-pool ``` # Usage ```ts import {ObjectPool} from '@smikhalevski/object-pool'; const pool = new ObjectPool(() => { // Create and return a heavy object. }, (value) => { // Reset the released object. }); // Prepare 100 heavy objects. pool.allocate(100); // Take a heavy object from the pool. const heavyObject = pool.take(); // Return heavy object back to the pool. pool.release(heavyObject); ```