Can I drain the pending queue without running them?
Can I drain the pending queue without running them?
About sindresorhus/p-limit · 2 messages · last activity 7/20/2026
Yes, you can drain the pending queue without running the tasks using the limit.clearQueue() method. This discards all pending promises that are waiting to run.
From the documentation [readme.md:L96-L106]:
Discard pending promises that are waiting to run.
This might be useful if you want to tear down the queue at the end of your program's lifecycle or discard any function calls referencing an intermediary state of your app.
Note: This does not cancel promises that are already running.
The key point is that clearQueue() only affects pending tasks (those queued but not yet started). Tasks that are already running will continue to completion.
If you want pending tasks to be explicitly rejected instead of just discarded, you can use the rejectOnClear option when creating the limiter [index.d.ts:L101-L106]:
const limit = pLimit({concurrency: 1, rejectOnClear: true});
limit.clearQueue(); // Pending tasks will reject with AbortError
This is particularly useful if you're awaiting the promises (e.g., with Promise.all), so pending tasks don't remain unresolved after clearing.
FOLLOW_UPS:
- How does activeCount differ from pendingCount?
- What happens to already-running promises on clearQueue?
- Can I detect when a task was discarded by clearQueue?
Want to ask your own question?
Open chat for sindresorhus/p-limitPublic Q&A. Generated by RepoPilot from the actual source of sindresorhus/p-limit. AI answers can be incomplete or stale — verify before relying on them.