Registry / storage / queue2

queue2

JSON →
library0.2.1jsnpmunverified

queue2.js v0.2.1 is a specialized Node.js queue data structure that combines unordered and ordered queuing with injection capabilities. Created by fent, it allows tasks to be executed concurrently with a configurable concurrency limit while supporting ordered processing through task injection. The first worker handles unordered tasks with an inject method to replace the current task with a sequence of ordered tasks. It requires Node >=4 and has no external dependencies. The package is in maintenance mode with no recent updates, and its API includes event emitters for error, drain, full, and empty events. It is a niche solution for specific use cases like asynchronous file reading with ordered subdirectory traversal.

npm install queue2
INSTALL
IMPORT
SIG · QUEUE2
Q
queue2
storagejavascriptv0.2.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.

Queue2
import { Queue2 } from 'queue2'
const Queue2 = require('queue2').Queue2;
ESM import is correct for modern Node. Default import does not exist; Queue2 is a named export.
Queue2
const { Queue2 } = require('queue2');
const Queue2 = require('queue2');
CommonJS require with destructuring works. Direct require returns the class as the module.exports, so 'const Queue2 = require('queue2');' also works, but destructuring is more explicit.
default
import Queue2 from 'queue2';
import { Queue2 } from 'queue2';
The package does not export a default. Only named export 'Queue2' exists. This import will result in undefined.

Creates a Queue2 with two workers and concurrency 2, pushes unordered tasks, and handles completion via callback and drain event.

import { Queue2 } from 'queue2'; const worker1 = (a, b, callback) => { // Simulate async work setTimeout(() => { callback(null, a + b); }, 100); }; const worker2 = (task, callback) => { // ordered processing console.log('Processing:', task); callback(null); }; const queue = new Queue2(worker1, worker2, 2); queue.push(1, 2, (err, result) => { if (err) throw err; console.log('Result:', result); }); queue.push(3, 4); queue.on('drain', () => { console.log('All tasks completed'); queue.die(); });
Debug
Known issues
gotchaIn first worker, calling both inject() and callback() will cause undefined behavior. When inject is used, callback must not be called.
fix
Check if this.inject was called before calling callback, or use inject only without callback.
affects: >=0.0.0
gotchapush() with a callback function as the last argument only works if the callback position matches the first worker's callback parameter. If first worker expects multiple data arguments, the callback must be the last data argument.
fix
Ensure the callback is the last argument matching worker1's callback position.
affects: >=0.0.0
deprecatedPackage is in maintenance mode; no updates since 2016. Node >=4 is required, may not work on newer Node versions without --experimental-modules.
fix
Consider migrating to modern alternatives like p-limit or async.queue.
affects: >=0.2.1
Errors
Common errors & fixes
TypeError: Queue2 is not a constructor
Incorrect import: using default import when package exports named export.
fix
Import with named import: import { Queue2 } from 'queue2';
Error [ERR_REQUIRE_ESM]: require() of ES Module not supported
Using CommonJS require on an ESM-only package or vice versa.
fix
Use dynamic import() for ESM: const { Queue2 } = await import('queue2'); or set type:"module" in package.json.
Unhandled 'error' event: [Error: ...]
Error occurred in a task without a push callback and no error event listener.
fix
Attach a listener: queue.on('error', (err) => console.error(err));
Upgrade
Version history
0.2.1latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
15 hits · last 30 days
node
14
OpenAI (training)
1
Resources
packagequeue2
queue2 — npm install queue2 · libregistry