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.

devops
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.

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.

import PQueue from 'p-queue'

PriorityQueue is a named export, not a default export or a subpath export.

import { PriorityQueue } from 'p-queue'

QueueAddOptions is a TypeScript type; use type-only import to avoid runtime errors.

import type { QueueAddOptions } from 'p-queue'

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 footguns
breakingIn v7, p-queue became ESM-only and no longer supports CommonJS require().
deprecatedThe 'queueClass' option is deprecated in v6.2+ and will be removed in v8.
gotchaWhen using .addAll(), the returned promise resolves when ALL tasks complete, not when they are added.
gotchaIf autoStart is false, tasks will not run until .start() is called. Calling .add() without .start() will queue tasks but never execute them.
gotchaThe 'timeout' option in .add() only works if the task function returns a promise. If it returns a non-promise value, timeout is ignored.
Upgrade
Version history

Breaking-change detection hasn't run for this library yet.

Audit
Security & dependencies

CVE tracking and dependency tree are planned for a later release.

Agent activity
9 hits · last 30 days
gptbot
3
mj12bot
1
Resources