queue-pool

Queue-Pool

Pool works as queue or stack.

Queue-Pool Is pool of elements, implements major Array methods. With ability to auto-adjust length.

Why?

If you handle a group of incoming streams of chunks, process them in a pool, there is a need to release them in stack or queue order.

Getting Started

npm install queue-pool

Usage

import QPool from "queue-pool";

const qpool = new QPool(options);

options

Methods

Example

const qpool = new QPool();
qpool.push("pigs, "); // pigs,
qpool.push("goats, "); // pigs, goats,
qpool.push("sheep."); // pigs, goats, sheep.
qpool.shift(); // goats, sheep.
qpool.pop(); // goats,
qpool.unshift("sheep, "); // sheep, goats,
qpool.elementsLength(); // 2
qpool.elementsSize(); // [7 , 7]
qpool.length(); // 14

with queue

const qpool = new QPool({ maxIn: 5 });
for (let i = 0; i < 10; i++) qpool.push(`${i} `);
qpool.get(); // 0 1 2 3 4 5 6 7 8 9
qpool.process("last-element");
qpool.get(); // 6 7 8 9 last-element

with stack and callback

const qpool = new QPool({ maxIn: 5 });
for (let i = 0; i < 10; i++) qpool.push(`${i} `);
qpool.get(); // 0 1 2 3 4 5 6 7 8 9
qpool.process("last-element", "stack", (get) => {
  console.log(get); //  0, 1, 2, 3 last-element
});

Tests

test

License

This project is licensed under the MIT License