Registry / testing / p-queue

p-queue

JSON →
library9.3.0jsnpmunverified

Promise queue with concurrency control, version 9.3.0. Feature-complete library by Sindre Sorhus for rate-limiting async operations. Useful for REST API calls, CPU/memory intensive tasks, and batch processing. Supports concurrency limits, per-task timeouts, priority queuing, and rate limiting via interval caps. ESM-only since v7; requires Node.js >=20. Alternative to bottleneck, async.queue, or p-limit with richer scheduling features.

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

ESM-only since v7; CommonJS require() will fail with ERR_REQUIRE_ESM.

import PQueue from 'p-queue'

Named export; path-based imports are not supported.

import { PriorityQueue } from 'p-queue'

Default export is the class; named export PQueue does not exist. For types, use import PQueue from 'p-queue'.

import PQueue from 'p-queue'

Creates a queue with concurrency 2 and rate limit (5 requests/sec). Adds fetch tasks and waits for all results.

import PQueue from 'p-queue'; const queue = new PQueue({ concurrency: 2, interval: 1000, intervalCap: 5 }); async function fetchData(url) { const response = await fetch(url); return response.json(); } async function main() { const urls = ['https://api.example.com/1', 'https://api.example.com/2', 'https://api.example.com/3']; const results = await Promise.all(urls.map(url => queue.add(() => fetchData(url)))); console.log(results); } main().catch(console.error);
Debug
Known footguns
breakingp-queue v7 is ESM-only. CommonJS require() will throw ERR_REQUIRE_ESM.
breakingp-queue v7 drops Node.js <16 support. v9 requires Node.js >=20.
deprecatedcustom ignore method is deprecated in v7+; implement via queueClass with priority.
gotchaDefault export is the class PQueue, not a factory function. Named export PQueue does not exist.
gotchaTimeoutError is not exported; catch generic Error and check message.
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
8 hits · last 30 days
gptbot
3
Resources