Registry / devops / run-queue

run-queue

JSON →
library2.0.1jsnpmunverified

A promise-based, dynamic priority queue runner with concurrency limiting for Node.js. Version 2.0.1 is stable but receives only sporadic maintenance. It allows adding jobs with integer priorities, ensures that all jobs of a lower priority complete before higher priorities execute, and dynamically switches back to lower priorities if new jobs are added. Supports configurable concurrency (default 1) and custom Promise implementations. Lightweight with no runtime dependencies.

npm install run-queue
INSTALL
IMPORT
SIG · RUN-QUEUE
R
run-queue
devopsjavascriptv2.0.1
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.

RunQueue
const RunQueue = require('run-queue')
import RunQueue from 'run-queue'; // ESM not supported
Package is CJS-only; no ESM exports.
RunQueue
import pkg from 'run-queue'; const RunQueue = pkg; // or const { RunQueue } = require('run-queue')
import { RunQueue } from 'run-queue'; // named import not available
Default import only; no named exports.
queue
const { add, run } = require('run-queue'); // No, RunQueue is a class
Queue is not exported; must instantiate RunQueue.
RunQueue is a class, not a factory function.

Creates a queue with concurrency 2, adds jobs at priorities 0 and 1, runs them, and logs completion.

const RunQueue = require('run-queue'); const queue = new RunQueue({ maxConcurrency: 2, Promise: require('bluebird') // optional custom Promise }); let completed = 0; const log = (id) => new Promise((resolve) => { setTimeout(() => { completed++; console.log(`Job ${id} done (${completed})`); resolve(); }, 100); }); queue.add(0, log, ['A']); queue.add(1, log, ['B']); // B waits for A queue.add(0, log, ['C']); // C runs before B queue.run().then(() => { console.log('All done'); }).catch(err => { console.error('Queue failed:', err); });
Debug
Known issues
gotchaPriority behavior: All jobs of a lower priority must finish before any jobs of a higher priority start. Adding new lower-priority jobs during higher-priority execution will cause the queue to switch back to lower priority, delaying higher-priority jobs.
fix
Be mindful of dynamic job addition; plan priorities accordingly or avoid adding lower-priority jobs while higher priorities are running.
affects: >=1.0.0
gotchamaxConcurrency: 1 is default. If you expect concurrent execution, you must explicitly set maxConcurrency > 1.
fix
Set `maxConcurrency` option when creating the queue.
affects: >=1.0.0
deprecatedThe callback-style `fn(args, next)` pattern is supported but deprecated. Use async functions returning Promises instead.
fix
Return a Promise from your job function instead of calling a `next` callback.
affects: >=2.0.0
Errors
Common errors & fixes
TypeError: queue.add is not a function
Queue not properly instantiated; missing `new` keyword.
fix
Use `new RunQueue(options)` to create the queue.
ReferenceError: require is not defined
Trying to use require in an ES module environment.
fix
Use dynamic import: `const RunQueue = (await import('run-queue')).default;`
Upgrade
Version history
2.0.1latest on npm
Audit
Dependencies

No dependency data recorded yet.

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