yapool: Simple Object Pool

1.0.0 · maintenance · verified Wed Apr 22

yapool is a minimalist JavaScript object pooling library, currently at version 1.0.0. It provides a basic linked-list implementation for managing reusable objects, focusing on extreme simplicity over feature richness. Unlike more comprehensive alternatives, yapool offers a 'dead-simple' API for adding and removing objects. Its primary differentiator is its minimal footprint and straightforward approach, making it suitable for scenarios where `n` (the number of objects in the pool) is small. Developers should be aware that operations like `remove` have `O(n)` complexity, which limits its applicability for very large lists. Given its simplicity and the project's age (last published in 2014), its release cadence is very stable or infrequent, suggesting a maintenance-only status rather than active feature development.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates initializing a new Pool, adding and removing objects, and checking the pool's length.

const Pool = require('yapool');

const myObjectPool = new Pool();

// Add objects to the pool
const obj1 = { id: 1, value: 'alpha' };
const obj2 = { id: 2, value: 'beta' };
myObjectPool.add(obj1);
myObjectPool.add(obj2);

console.log(`Pool length after adding: ${myObjectPool.length}`); // Expected: 2

// Remove an object from the pool
myObjectPool.remove(obj1);

console.log(`Pool length after removing obj1: ${myObjectPool.length}`); // Expected: 1

// Attempt to remove an object not in the pool (it will be a no-op)
const obj3 = { id: 3, value: 'gamma' };
myObjectPool.remove(obj3);

console.log(`Pool length after attempting to remove obj3: ${myObjectPool.length}`); // Expected: 1

// The remaining object in the pool is obj2
// (Note: yapool does not provide a way to 'get' an object, only add/remove)

view raw JSON →