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/6/2026
Yes, you can drain the pending queue without running the tasks using the clearQueue() method [index.d.ts:L18-L28].
When you call limit.clearQueue(), it discards all pending promises that are waiting to run. As documented in the README [readme.md:L96-L106], this method:
- Discards pending promises — tasks waiting to run are removed from the queue and never execute
- Does NOT cancel running tasks — promises already in execution will continue to completion
- Leaves promises unresolved by default — pending promises simply never settle unless you enable the
rejectOnClearoption
If you want pending tasks to be explicitly rejected instead of left hanging, you can enable the rejectOnClear option when creating the limiter:
const limit = pLimit({concurrency: 1, rejectOnClear: true});
With rejectOnClear: true, pending promises are rejected with an AbortError when clearQueue() is called [readme.md:L43-L47].
A practical example is shown in the recipes for graceful shutdown [recipes.md:L76-L115], where clearQueue() discards pending tasks while allowing already-running tasks to complete.
FOLLOW_UPS:
- How does clearQueue() interact with activeCount and pendingCount?
- What happens to already-running tasks during clearQueue()?
- Can I see which tasks were 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.