Registry / testing / np-queue

np-queue

JSON →
library2.0.0jsnpmunverified

np-queue (v2.0.0) is a lightweight Promise-based queue library for controlling task concurrency and pausing/resuming execution. It supports TypeScript types and provides an API for adding tasks, wrapping functions to limit concurrency, and queue lifecycle management. Key differentiators: minimal API surface, pause/resume functionality, and optional task keys for deduplication. Release cadence appears irregular (last release unknown). Suitable for Node.js and browser environments.

npm install np-queue
INSTALL
IMPORT
SIG · NP-QUEUE
N
np-queue
testingjavascriptv2.0.0
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.

Queue
import Queue from 'np-queue'
import { Queue } from 'np-queue'
Default export, not named export.
Queue (CommonJS)
const Queue = require('np-queue').default
const Queue = require('np-queue')
CommonJS require requires .default property to access default export.
Queue (TypeScript)
import Queue from 'np-queue'
Same as ESM, types ship with package.

Creates a queue with concurrency 2, adds three tasks, demonstrates pause/resume, and wraps a function.

import Queue from 'np-queue'; const queue = new Queue({ concurrency: 2 }); const task1 = () => new Promise(resolve => setTimeout(() => resolve(1), 1000)); const task2 = () => new Promise(resolve => setTimeout(() => resolve(2), 1000)); const task3 = () => new Promise(resolve => setTimeout(() => resolve(3), 1000)); queue.add(task1).then(console.log); queue.add(task2).then(console.log); queue.add(task3).then(console.log); // Output: 1, 2, and then 3 after 1 second (concurrency 2 means two tasks run simultaneously) queue.pause(); // queue is paused, tasks are deferred queue.resume(); // resumes execution const wrapped = queue.wrap(task1); wrapped().then(console.log);
Debug
Known issues
gotchaUsing 'await' with queue.add() inside an async function causes serial execution instead of concurrent.
fix
Do not await add() if you want concurrent execution; chain via .then() or use Promise.all().
affects: *
gotchaTask keys must not be undefined; providing undefined as key will be ignored.
fix
Provide a defined key (e.g., string or number) to enable deduplication.
affects: *
breakingv2.0.0 changed the default concurrency from Infinity to 1.
fix
If you relied on default Infinity, specify concurrency: Infinity explicitly.
affects: >=2.0.0
gotchaqueue.all() does not guarantee order; results may be in different order than added tasks.
fix
Use queue.add() and track promises manually for ordered results.
affects: *
Errors
Common errors & fixes
import { Queue } from 'np-queue' yields undefined
Queue is a default export, not a named export.
fix
Use import Queue from 'np-queue' instead.
TypeError: require(...) is not a constructor (CommonJS)
Using require without .default gives the module object, not the default export.
fix
Use const Queue = require('np-queue').default;
Tasks are running one by one even though I set concurrency > 1
Using await queue.add() inside an async function serializes the adds.
fix
Do not await; use .then() or add them without await.
Upgrade
Version history
2.0.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
6 hits · last 30 days
node
6
Resources
np-queue — npm install np-queue · libregistry