Registry / devops / p-queue-multi

p-queue-multi

JSON →
library8.0.4jsnpmunverified

A promise queue with concurrency control, rate-limiting, priority, timeout, and abort support. Current stable version is 8.0.4, a fork of the popular p-queue library modified to support both CommonJS and ESM without the original's ESM-only restriction. Released in lockstep with upstream but may bump minor versions independently. Key differentiators: works in CJS and ESM (unlike p-queue v7+ which is ESM-only), EventEmitter3-based, supports interval-based rate limiting, priority queuing, and AbortSignal cancellation. Useful for rate-limiting async operations like REST API calls or CPU/memory intensive tasks.

npm install p-queue-multi
INSTALL
IMPORT
SIG · P-QUEUE-MULTI
P
p-queue-multi
devopsjavascriptv8.0.4
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.

PQueue
import PQueue from 'p-queue-multi'
const PQueue = require('p-queue-multi').default
Default export. In CommonJS, you can use const PQueue = require('p-queue-multi').default or set the package in a way that allows require directly. The package supports both CJS and ESM.
PQueue as named
import { default as PQueue } from 'p-queue-multi'
There is no named export; only default export.
Type: DefaultAddOptions
import type { DefaultAddOptions } from 'p-queue-multi'
TypeScript types are included. Types are exported under the same path.
PriorityQueue
import { PriorityQueue } from 'p-queue-multi'
const PriorityQueue = require('p-queue-multi').PriorityQueue
PriorityQueue is a named export (a class implementing queue interface). In CJS, use const { PriorityQueue } = require('p-queue-multi').

Creates a PQueue with concurrency 1 and rate limiting, adds a task with priority, and logs the result.

import PQueue from 'p-queue-multi'; import got from 'got'; const queue = new PQueue({ concurrency: 1, interval: 1000, intervalCap: 5 }); async function example() { const result = await queue.add(async () => { const response = await got('https://api.example.com/data', { timeout: 5000 }); return response.body; }, { priority: 10 }); console.log('Result:', result); } example().catch(console.error);
Debug
Known issues
breakingp-queue-multi v7+ breaks CommonJS require without .default
fix
Use require('p-queue-multi').default instead of require('p-queue-multi') or switch to dynamic import()
affects: >=7.0.0
breakingp-queue-multi v8+ requires Node.js >=18
fix
Upgrade Node.js to version 18 or later
affects: >=8.0.0
deprecatedThe `timeout` option without `throwOnTimeout: true` will still resolve the promise, not reject
fix
Set throwOnTimeout: true if you want timeout to reject the promise
affects: >=1.0.0
gotchaUnhandled promise rejections from queue.add() may crash process if task throws
fix
Always attach .catch() to the promise returned by queue.add()
affects: >=1.0.0
gotchaThe `signal` option only cancels pending tasks, not running ones; abortSignal must be handled by the task itself
fix
Pass the signal to your async function and listen for abort events
affects: >=6.0.0
gotchaInterval-based rate limiting resets per interval, but carryoverConcurrencyCount defaults to false, meaning pending tasks from previous interval are not counted
fix
Set carryoverConcurrencyCount: true if pending tasks should count toward intervalCap
affects: >=5.0.0
Errors
Common errors & fixes
p-queue-multi is not a constructor
In CommonJS, require returns an ESM module with default export as module.exports.default
fix
Use const PQueue = require('p-queue-multi').default
Cannot find module 'p-queue-multi'
Package not installed or Node.js version <18
fix
Run npm install p-queue-multi and ensure Node.js >=18
TypeError: queue.add is not a function
Instantiating PQueue incorrectly (e.g., using new on default object without .default)
fix
Ensure you're using the PQueue class correctly: const queue = new PQueue()
UnhandledPromiseRejectionWarning
Task added to queue rejected and no .catch() attached to the returned promise
fix
Add .catch() to queue.add() promise or use try/catch with await
AbortError: The operation was aborted
AbortSignal was triggered before task started
fix
Check if the abort signal is being correctly used and handle the rejection gracefully
Upgrade
Version history
8.0.4latest on npm
Audit
Dependencies
eventemitter3requiredPQueue extends EventEmitter3 for event handling
Agent activity
2 hits · last 30 days
node
2
Resources