Registry / devops / async-parallel-queue

async-parallel-queue

JSON →
library1.0.3jsnpmunverified

A lightweight queue for executing async functions in parallel with configurable concurrency. Version 1.0.3. Provides methods like add, fn, waitIdle, pause, start, and status checks. Differentiated by simplicity and zero dependencies, focusing on a functional API without event emitters or Promise-based wrappers.

npm install async-parallel-queue
INSTALL
IMPORT
SIG · ASYNC-PARALLEL-QUE
A
async-parallel-queue
devopsjavascriptv1.0.3
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
const Queue = require('async-parallel-queue'); const queue = new Queue({concurrency: 10});
import Queue from 'async-parallel-queue';
Package is CommonJS only; no named export. Use require() or dynamic import().
Queue
const { default: Queue } = await import('async-parallel-queue'); const queue = new Queue({concurrency: 10});
const Queue = require('async-parallel-queue').default;
For ESM, use dynamic import with .default.
queue.add
queue.add(async () => fetch('https://example.com'));
queue.add(fetch('https://example.com'));
Pass an async function, not a Promise.
queue.fn
const download = queue.fn(async (url) => fetch(url));
const download = queue.fn((url) => fetch(url));
fn expects an async function; wrapping in async ensures proper handling.

Creates a queue with concurrency 3, adds three async tasks with varying delays, and waits for the queue to finish.

const Queue = require('async-parallel-queue'); const queue = new Queue({ concurrency: 3 }); // Simulate async tasks queue.add(async () => { await new Promise(resolve => setTimeout(resolve, 100)); console.log('Task 1 done'); }); queue.add(async () => { await new Promise(resolve => setTimeout(resolve, 50)); console.log('Task 2 done'); }); queue.add(async () => { await new Promise(resolve => setTimeout(resolve, 200)); console.log('Task 3 done'); }); // Wait for all tasks to complete await queue.waitIdle(); console.log('All tasks completed');
Debug
Known issues
gotchaThe queue does not handle rejections from tasks; unhandled promise rejections will occur if no catch is attached.
fix
Wrap task functions in try-catch or attach .catch() to the returned promise from queue.add.
affects: >=1.0.0
deprecatedThe waitIdle method may hang if tasks keep adding new tasks (infinite loop).
fix
Ensure no new tasks are added after calling waitIdle, or set a timeout.
affects: >=1.0.0
gotchaWhen using queue.add with args, the args array is passed as spread arguments to the function, not as an array.
fix
queue.add(async (a, b) => a + b, {args: [1, 2]}) returns 3 (not 1+2).
affects: >=1.0.0
breakingIn version 1.0.0, the constructor required an options object with concurrency. No default concurrency is assumed.
fix
Always pass { concurrency: number } to new Queue().
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: Queue is not a constructor
Trying to use default import from an ESM context without dynamic import.
fix
const Queue = require('async-parallel-queue');
Error: concurrency must be a positive integer
Passing a non-integer or negative concurrency value to the Queue constructor.
fix
new Queue({ concurrency: 3 }); // integer > 0
UnhandledPromiseRejectionWarning: ...
Task function threw an error and no .catch was attached.
fix
queue.add(async () => { ... }).catch(err => console.error(err));
queue.waitIdle never resolves
New tasks are being added while waiting for idle.
fix
Stop adding tasks before calling waitIdle, or use a timeout.
Upgrade
Version history
1.0.3latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
10 hits · last 30 days
node
8
Amazon
1
OpenAI (training)
1
Resources
async-parallel-queue — npm install async-parallel-queue · libregistry