Registry / devops / queue
library7.0.0jsnpmunverified

Asynchronous function queue with adjustable concurrency. Version 7.0.0. Allows controlling the number of concurrently running async jobs, with support for timeouts, event listeners, and array-like API (push, unshift, splice, etc.). Jobs can use callbacks or return promises. Ships TypeScript types. Maintained actively on GitHub.

npm install queue
INSTALL
IMPORT
SIG · QUEUE
Q
queue
devopsjavascriptv7.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 'queue'
✗ import { Queue } from 'queue'
Default export; named import will fail. TypeScript types support default import.
Queue
✓ const Queue = require('queue')
✗ const { Queue } = require('queue')
CommonJS: require returns the class directly, not an object.
Queue
✓ import Queue from 'queue'
✗ import * as Queue from 'queue'
Namespace import not valid; default import is correct.

Creates a queue with concurrency 2, adds three jobs (callback and promise style), and starts processing.

import Queue from 'queue' const q = new Queue({ concurrency: 2, autostart: true }) q.push(cb => { setTimeout(() => { console.log('job 1') cb() }, 100) }) q.push(() => { return new Promise(resolve => { setTimeout(() => { console.log('job 2') resolve() }, 200) }) }) q.push(cb => { setTimeout(() => { console.log('job 3') cb() }, 50) }) // Wait for all jobs to finish q.start(err => { if (err) throw err console.log('all done') })
Debug
Known issues
breakingSince v6, the package is ESM-only. require() will fail in Node < 12 or without bundler.
fix
Use import or upgrade to Node >=12 with type:module in package.json, or use bundler like Webpack/Rollup.
affects: >=6.0.0
deprecatedEvent names 'success' and 'error' have been deprecated since v6. Use 'end' and 'error' instead.
fix
Listen to 'end' event for completion and check error parameter, or use promise returned by start().
affects: >=6.0.0 <7.0.0
gotchaq.slice() does not copy the queue; it returns a shallow slice of the queue's internal array, but modifying it will affect the original queue.
fix
Use q.toArray() or manually copy the array if you need an independent copy.
affects: >=1.0.0
gotchaq.start() returns a promise if no callback is provided. Mixing callback and promise patterns can lead to unhandled rejections.
fix
Either always use callback or always use .then().catch() on the returned promise.
affects: >=6.0.0
breakingIn v7, the 'timeout' property on a job must be set directly on the function (e.g., job.timeout = 100). Passing options in an object is no longer supported.
fix
Set timeout as a property on the job function itself.
affects: >=7.0.0
gotchaJobs that return a promise and also call a callback may cause double resolution. The queue resolves on the first completion (callback or promise).
fix
Use only one completion mechanism per job.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: queue_1.default is not a constructor
Using named import `import { Queue } from 'queue'` instead of default import.
fix
Use `import Queue from 'queue'`.
Error [ERR_REQUIRE_ESM]: require() of ES Module /path/node_modules/queue/index.js from /path/file.js not supported.
Using require() on an ESM-only module (v6+).
fix
Use import or compile with bundler (Webpack/Rollup).
TimeoutError: Job timed out after 100ms
Timeout default or set too low; job did not complete in time.
fix
Increase timeout or set per-job timeout via job.timeout property.
job is not a function
Adding non-function items to the queue (e.g., objects, strings).
fix
Ensure each pushed item is a function that accepts a callback or returns a promise.
Upgrade
Version history
7.0.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
4 hits · last 30 days
node
4
Resources
packagequeue ↗
queue — npm install queue · libregistry