Registry / testing / best-queue

best-queue

JSON →
library3.0.7jsnpmunverified

best-queue is a lightweight, TypeScript-friendly library for controlling asynchronous task execution with concurrency limits, intervals, and error handling. Current stable version is 3.0.7, released under MIT license. It allows developers to create a queue that processes tasks (including Promises) with configurable max concurrency (default 1) and interval between tasks (default 0ms). Key differentiators include optional error recording (recordError mode to continue on failure), pause/resume functionality, and support for both ESM and CommonJS. Compared to similar libraries like p-limit or promise-queue, best-queue provides a single function API with built-in interval control and batch concurrency with fallback to slow tasks.

npm install best-queue
INSTALL
IMPORT
SIG · BEST-QUEUE
B
best-queue
testingjavascriptv3.0.7
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.

createQueue
import { createQueue } from 'best-queue'
import createQueue from 'best-queue'
ESM default import is incorrect; use named import. CommonJS require also works: const { createQueue } = require('best-queue').
pause
import { createQueue } from 'best-queue'; const queue = createQueue([]); queue.pause()
import { pause } from 'best-queue'
pause is a method on the queue object returned by createQueue, not a named export.
resume
import { createQueue } from 'best-queue'; const queue = createQueue([]); queue.resume()
import { resume } from 'best-queue'
resume is a method on the queue object, not a standalone export.

Creates a queue with concurrency 2 and 1-second interval, processing an array of synchronous values with error recording enabled.

import { createQueue } from 'best-queue'; async function main() { const tasks = [1, 2, 3, 4, 5]; const results = await createQueue(tasks, { max: 2, interval: 1000, recordError: true }); console.log(results); // [1,2,3,4,5] or errors if any } main().catch(console.error);
Debug
Known issues
gotchaWhen `recordError: false` (default), any rejected promise in the task array will reject the entire queue and stop processing remaining tasks.
fix
Set `recordError: true` to continue on errors; errors are collected in the results array instead of rejecting.
affects: >=0.0.0
gotchaThe `max` option defaults to 1 but cannot be less than 1; setting it to 0 or negative will be clamped to 1.
fix
Always provide a positive integer for max parallel tasks.
affects: >=3.0.0
gotchaThe `interval` is applied between tasks, not between batches. If max > 1, the interval waits after the last task in a batch finishes before starting the next batch.
fix
Adjust interval logic if expecting per-task delay; this is by design for concurrency.
affects: >=3.0.0
breakingVersion 2.x used a different API (class-based Queue); version 3.0 introduced createQueue as the main export and removed default export.
fix
Migrate from `import Queue from 'best-queue'` to `import { createQueue } from 'best-queue'`.
affects: <3.0.0
Errors
Common errors & fixes
import createQueue from 'best-queue'; // TypeError: createQueue is not a function
Default import used, but the package only exports a named export `createQueue`.
fix
Replace with: import { createQueue } from 'best-queue';
const { createQueue } = require('best-queue'); // TypeError: Cannot destructure property 'createQueue' of 'require(...)' as it is undefined.
Mixed ESM and CJS; in some environments, the CJS build might not expose the named export correctly.
fix
Ensure you are using a version that provides proper CJS support (>=3.0.0). For Node.js, use ESM imports or ensure transpilation.
Upgrade
Version history
3.0.7latest on npm
Audit
Dependencies
best-queueoptionalNo external runtime dependencies.
Agent activity
21 hits · last 30 days
node
18
Amazon
1
OpenAI (training)
1
Resources
best-queue — npm install best-queue · libregistry