Registry / devops / promise-queue-manager

promise-queue-manager

JSON →
library3.0.5jsnpmunverified

A queue manager for concurrent promise execution with zero external dependencies. Provides fine-grained control over concurrency and error handling, supporting both function lists and item-based processing. Version 3.0.5 uses a config object and requires promises to be wrapped in functions to avoid early execution. Uses EventEmitter for event-driven flow. Suitable for batch processing or rate-limiting async tasks. Differentiators include zero dependencies, TypeScript types, and ability to cancel queue mid-execution.

npm install promise-queue-manager
INSTALL
IMPORT
SIG · PROMISE-QUEUE-MANA
P
promise-queue-manager
devopsjavascriptv3.0.5
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.

PromiseQueue
import { PromiseQueue } from 'promise-queue-manager'
const PromiseQueue = require('promise-queue-manager')
ESM import is recommended; CommonJS require works but may have typing issues.
PromiseQueueItemResponse
import { PromiseQueueItemResponse } from 'promise-queue-manager'
Type-only export for TypeScript users.
PromiseQueueConfig
import { PromiseQueueConfig } from 'promise-queue-manager'
Type-only export for the config object.
PromiseQueue.EVENTS
import { PromiseQueue } from 'promise-queue-manager'; const events = PromiseQueue.EVENTS
import { EVENTS } from 'promise-queue-manager'
EVENTS is a static property on the PromiseQueue class, not a separate export.

Creates a queue with a promise function and an array of items, listens for processed events, and starts processing.

import { PromiseQueue } from 'promise-queue-manager'; const save = async (data: any) => { // Simulate async work return new Promise((resolve) => setTimeout(() => resolve(data), 100)); }; const items = [1, 2, 3, 4, 5]; const config = { promise: save, items: items, concurrence: 2, shouldStopOnError: false, }; const queue = new PromiseQueue<any>(config); queue.on(PromiseQueue.EVENTS.ITEM_PROCESSED, (response) => { console.log('Processed:', response.item, 'result:', response.result); }); queue.on(PromiseQueue.EVENTS.QUEUE_PROCESSED, () => { console.log('All items processed.'); }); queue.start();
Debug
Known issues
breakingIn v3.x.x, the constructor parameters 'concurrence' and 'shouldStopOnError' must be passed as part of a config object instead of separate arguments.
fix
Change constructor call from 'new PromiseQueue(concurrence, shouldStopOnError)' to 'new PromiseQueue({concurrence, shouldStopOnError})'.
affects: >=3.0.0
breakingIn v3.x.x, the 'promises' list must contain functions that return promises, not promises themselves, to avoid early execution.
fix
Wrap each promise in a function: 'items.map(item => () => save(item))'.
affects: >=3.0.0
breakingIn v2.x.x, 'PromiseQueue.EVENTS.QUEUE_PROCESSED' is now emitted even when 'shouldStopOnError' is true.
fix
Ensure your listener handles QUEUE_PROCESSED regardless of error handling setting.
affects: >=2.0.0 <3.0.0
gotchaWhen using the 'promises' configuration, each element must be a function that returns a promise. If you pass a promise directly, it will be executed immediately and likely cause unexpected behavior.
fix
Always wrap promises in arrow functions: '() => myPromise'.
affects: >=3.0.0
gotchaThe 'cancel' method stops processing but does not reject pending promises; they may still resolve.
fix
If you need to abort async operations, implement cancellation logic in the promise functions.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: PromiseQueue is not a constructor
Using CommonJS require incorrectly or import failure.
fix
Use 'import { PromiseQueue } from 'promise-queue-manager'' in ESM, or 'const { PromiseQueue } = require('promise-queue-manager')' in CJS.
Property 'EVENTS' does not exist on type 'typeof PromiseQueue'
Importing EVENTS as a separate named export instead of accessing via class.
fix
Use 'PromiseQueue.EVENTS' after importing PromiseQueue.
Argument of type '{ promise: ..., items: ... }' is not assignable to parameter of type 'PromiseQueueConfig'
Missing required property or type mismatch in config object.
fix
Ensure config includes either 'promises' (array of functions) or 'promise' + 'items'.
Upgrade
Version history
3.0.5latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
4 hits · last 30 days
node
4
Resources
promise-queue-manager — npm install promise-queue-manager · libregistry