RepoPilot

Is there a way to inspect the pending queue size?

About sindresorhus/p-limit · 2 messages · last activity 5/18/2026

Question

Is there a way to inspect the pending queue size?

RepoPilot

Yes, you can inspect the pending queue size using the limit.pendingCount property.

According to the TypeScript definitions [index.d.ts:L8-L11], pendingCount is a read-only property that returns "The number of promises that are waiting to run (i.e. their internal fn was not called yet)."

Here's a practical example from the recipes documentation [recipes.md:L191-L214]:

const limit = pLimit(5);
const progressInterval = setInterval(() => {
	console.log(`Running: ${limit.activeCount}, pending: ${limit.pendingCount}`);
}, 250);

This shows how you can use pendingCount to monitor how many tasks are queued and waiting to execute. There's also a test case [test.js:L180-L192] that demonstrates this:

test('clearQueue', async t => {
	const limit = pLimit(1);
	Array.from({length: 1}, () => limit(() => delay(1000)));
	Array.from({length: 3}, () => limit(() => delay(1000)));
	await Promise.resolve();
	t.is(limit.pendingCount, 3);
	limit.clearQueue();
	t.is(limit.pendingCount, 0);
});

FOLLOW_UPS:

  • How do I monitor activeCount alongside pendingCount?
  • Can I pause or cancel pending tasks in queue?
  • What happens to pending tasks if I clear the queue?

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.