Registry / devops / pm-queue

pm-queue

JSON →
library6.2.4jsnpmunverified

Promise queue with concurrency control for rate-limiting async operations. Stable version 6.2.4, ships TypeScript definitions, requires Node >=8. Actively maintained (by sindresorhus). Key differentiators: optional priority, interval-based rate limiting, timeout support, and custom queue classes. ESM-only since v7, but v6 supports both ESM and CJS.

npm install pm-queue
INSTALL
IMPORT
SIG · PM-QUEUE
P
pm-queue
devopsjavascriptv6.2.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.

default
import PQueue from 'p-queue'
const PQueue = require('p-queue')
p-queue v7+ is ESM-only; for v6 (CJS), use const { default: PQueue } = require('p-queue'). In TypeScript with ESM, import PQueue from 'p-queue' works directly.
PriorityQueue
import { PriorityQueue } from 'p-queue'
import PriorityQueue from 'p-queue/priority-queue'
PriorityQueue is a named export, not a default export or a subpath export.
type QueueAddOptions
import type { QueueAddOptions } from 'p-queue'
import { QueueAddOptions } from 'p-queue'
QueueAddOptions is a TypeScript type; use type-only import to avoid runtime errors.

Shows basic usage: create a queue with concurrency=2 and rate limit of 5 tasks per second, then add 10 async tasks.

import PQueue from 'p-queue'; const queue = new PQueue({ concurrency: 2, interval: 1000, intervalCap: 5 }); async function main() { const tasks = Array.from({ length: 10 }, (_, i) => async () => { await new Promise(resolve => setTimeout(resolve, 100)); return `Task ${i + 1} done`; }); const results = await Promise.all(tasks.map(task => queue.add(task))); console.log(results); } main().catch(console.error);
Debug
Known issues
breakingIn v7, p-queue became ESM-only and no longer supports CommonJS require().
fix
Update imports to ES module syntax: import PQueue from 'p-queue'. If you must use CJS, stick with v6.x or use dynamic import().
affects: >=7.0.0
deprecatedThe 'queueClass' option is deprecated in v6.2+ and will be removed in v8.
fix
Use the 'Queue' class option instead: new PQueue({ queue: new PriorityQueue() })
affects: >=6.2.0
gotchaWhen using .addAll(), the returned promise resolves when ALL tasks complete, not when they are added.
fix
Treat .addAll() similarly to Promise.all; it will reject if any task throws.
affects: *
gotchaIf autoStart is false, tasks will not run until .start() is called. Calling .add() without .start() will queue tasks but never execute them.
fix
Explicitly call queue.start() after adding tasks, or set autoStart: true in options.
affects: *
gotchaThe 'timeout' option in .add() only works if the task function returns a promise. If it returns a non-promise value, timeout is ignored.
fix
Ensure the function passed to .add() returns a promise (async or .then()).
affects: *
Errors
Common errors & fixes
TypeError: Class constructor PQueue cannot be invoked without 'new'
p-queue uses ES6 classes and must be instantiated with the 'new' keyword.
fix
Use new PQueue() instead of calling PQueue() without new.
Error: Cannot find module 'p-queue'
Package not installed or missing from node_modules.
fix
Run 'npm install p-queue' and ensure you are in the correct directory.
TypeError: queue.add is not a function
Using CommonJS require without default import syntax in v6.
fix
Use const { default: PQueue } = require('p-queue') or import PQueue from 'p-queue'.
Upgrade
Version history
6.2.4latest on npm
Audit
Dependencies
eventemitter3requiredPQueue extends EventEmitter3 to emit events like 'active' and 'idle'
Agent activity
2 hits · last 30 days
node
2
Resources
pm-queue — npm install pm-queue · libregistry