Registry / messaging / wait-queue

wait-queue

JSON →
library1.1.4jsnpmunverified

A JavaScript asynchronous queue that implements a producer-consumer pattern using ES6 classes and Promises. Version 1.1.4 (stable) provides methods like push, shift, pop, and unshift where shift and pop return Promises that resolve when items become available. Built on a LinkedList for efficient O(1) operations, it avoids the performance pitfalls of using Array.shift() on large arrays. Main differentiator: it's a lightweight, ready-to-use async queue without external dependencies, supporting both ESM imports and CommonJS requires.

npm install wait-queue
INSTALL
IMPORT
SIG · WAIT-QUEUE
W
wait-queue
messagingjavascriptv1.1.4
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

WaitQueue
import WaitQueue from 'wait-queue'
const { WaitQueue } = require('wait-queue')
ESM default export. CommonJS users should use `const WaitQueue = require('wait-queue')`.
WaitQueue (TypeScript)
import WaitQueue from 'wait-queue'; const wq = new WaitQueue<string>();
import { WaitQueue } from 'wait-queue'
TypeScript users import the default export and can supply a type parameter for item type.
WaitQueue (CommonJS)
const WaitQueue = require('wait-queue')
const { WaitQueue } = require('wait-queue')
CommonJS uses default require, not destructured. ESM is the primary module system.

Demonstrates async producer-consumer pattern using push and shift.

import WaitQueue from 'wait-queue'; const wq = new WaitQueue<string>(); async function worker() { for (let i = 0; i < 5; i++) { const item = await wq.shift(); console.log('Processed:', item); } } async function producer() { const items = ['a', 'b', 'c', 'd', 'e']; for (const item of items) { wq.push(item); console.log('Produced:', item); await new Promise(res => setTimeout(res, 100)); } } worker(); producer();
Debug
Known issues
gotchaCalling shift() or pop() on an empty queue will cause the Promise to never resolve if no item is ever pushed.
fix
Ensure items are pushed eventually, or use a timeout mechanism (not built-in).
affects: >=1.0.0
gotchaDo not modify wq.queue (a LinkedList) directly; it may cause unexpected behavior.
fix
Use the provided methods (push, shift, etc.) instead of mutating queue directly.
affects: >=1.0.0
gotchaThe empty() method does not clear listeners; use clearListeners() if you need to cancel waiting promises.
fix
After empty(), call clearListeners() to reject pending shift/pop promises.
affects: >=1.0.0
breakingVersion 1.0.0 introduced a breaking change: the internal data structure changed from Array to LinkedList.
fix
No API changes, but performance characteristics differ; benchmark your use case.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: WaitQueue is not a constructor
Using destructured require instead of default import/require.
fix
Use `const WaitQueue = require('wait-queue');` (CommonJS) or `import WaitQueue from 'wait-queue';` (ESM).
Cannot find module 'wait-queue'
Package not installed or import path is wrong.
fix
Run `npm install wait-queue` and use the correct import: `import WaitQueue from 'wait-queue';`.
shift() never resolves
Queue remains empty and no items are ever added.
fix
Ensure that push() is called somewhere in your code to add items.
Upgrade
Version history
1.1.4latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
19 hits · last 30 days
node
16
OpenAI (training)
1
Resources