simple-object-pool
Version:
Super lightweight implementation of factory-based object pool.\ There is no error handling if the same object is released into the pool to keep it fast.
45 lines (31 loc) • 988 B
Markdown
Super lightweight implementation of factory-based object pool.\
There is no error handling if the same object is released into the pool to keep it fast.
```js
import ObjectPool from "simple-object-pool";
const objPool = new ObjectPool(() => {
return { hello: "world" };
});
```
```js
const obj1 = objPool.get();
const obj2 = objPool.get();
const obj3 = objPool.get();
```
```js
objPool.release(obj1);
// put multiple objects back into the pool
objPool.releaseMany([obj2, obj3]);
console.log(objPool.size()); // 3
```
```js
objPool.clear();
console.log(objPool.size()); // 0
```
[](LICENSE)
All code and documentation are (c) 2023 Eugene Shumilin and released under the [MIT License](http://getify.mit-license.org/). A copy of the MIT License [is also included](LICENSE).