RepoPilot

Can I drain the pending queue without running them?

About sindresorhus/p-limit · 2 messages · last activity 6/8/2026

Question

Can I drain the pending queue without running them?

RepoPilot

Yes, you can drain the pending queue without running the pending promises using the clearQueue() method.

According to the README, limit.clearQueue() will "discard pending promises that are waiting to run." This means any promises in the queue that haven't started executing yet will be removed without being executed.

However, there's an important consideration: by default, when you call clearQueue(), the pending promises are simply discarded. If you want those pending tasks to be explicitly rejected (rather than left unresolved), you should initialize the limiter with the rejectOnClear option set to true:

const limit = pLimit({concurrency: 1, rejectOnClear: true});

With rejectOnClear: true, pending promises will be rejected with an AbortError when clearQueue() is called. This is recommended if you're awaiting the returned promises (for example with Promise.all), so pending tasks don't remain unresolved after clearing the queue.

FOLLOW_UPS:

  • What happens to currently running promises when clearQueue() is called?
  • How do I check how many promises are pending before clearing?
  • Does clearQueue() work with limit.map()?

Want to ask your own question?

Open chat for sindresorhus/p-limit

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