async-fifo-queue
Simple async FIFO queue implementation in modern Javascript with 0 dependency.
Installation
-
npm
npm install async-fifo-queue
-
yarn
yarn add async-fifo-queue
Usage
const Queue = ; // if no size specified, the queue size is infiniteconst q = ; // put an object into the queueawait q;await q; // get the objectconst item1 = await q; // item1 === "something"const item2 = await q; // item2 === "foobar" // simulating someone adding an item to the queue 1 sec later;// will wait 1 sec until the item is added into the queueconst item3 = await q; // item3 === "blabla" // put an object without waiting, will raise QueueFull Error if the queue is already fullq;// get an object without waiting, will raise QueueEmpty Error if the queue is emptyconst item4 = q;
The Queue object also has additionnal properties:
currSize
returns the current size of the queueisEmpty()
returns true if the queue is emptyisFull()
returns true if the queue is full
Tests
This project uses Jest.
npm run test