P-queue is a Node package that queues async or sync tasks with concurrency limits. It suits rate-limited API calls and similar workloads.
Overview
P-queue schedules functions that return promises or run synchronously, exposing how many tasks may run at once and how often new tasks may start. It targets scenarios such as throttling outbound HTTP requests or pacing CPU- or memory-heavy work in application code.
Options include per-task priorities, interval-based rate caps with fixed or sliding windows, timeouts that abort waiting or running work via AbortSignal, pause and start controls, and custom internal queue classes for alternative ordering policies.
The queue is an EventTarget, emitting lifecycle events for active, completed, error, empty, idle, and rate-limit states. Helpers such as onIdle, onEmpty, and onRateLimit return promises suitable for backpressure and shutdown coordination.
The package ships as native ESM with no runtime dependencies. Documentation notes that large server-side job processing may be better handled with a Redis-backed queue instead.
Key features
- Configurable concurrency limit
- Priority ordering for waiting tasks
- Interval rate limiting with strict mode
- Per-task and default timeouts
- AbortSignal cancellation
- Pause, start, and clear controls
- EventTarget progress events
- Zero npm dependencies
Use cases
- Throttle REST API requests in a client
- Limit parallel file or network operations
- Backpressure when producers outpace workers
- Ordered background task batches