How can I check the current number of active tasks?
How can I check the current number of active tasks?
About sindresorhus/p-limit · 2 messages · last activity 5/25/2026
You can check the current number of active tasks using the activeCount property on the limit function.
According to the TypeScript definitions [index.d.ts:L2-L4], activeCount is a read-only property that returns "The number of promises that are currently running."
Here's how you'd use it:
import pLimit from 'p-limit';
const limit = pLimit(5);
// ... queue some tasks ...
console.log(limit.activeCount); // Returns the number of currently running promises
A practical example from the recipes is progress reporting [recipes.md:L191-L214], which shows checking activeCount alongside pendingCount at intervals:
const progressInterval = setInterval(() => {
console.log(`Running: ${limit.activeCount}, pending: ${limit.pendingCount}`);
}, 250);
This allows you to monitor how many tasks are currently executing versus waiting in the queue.
FOLLOW_UPS:
- How do I check the number of pending tasks?
- What's the difference between activeCount and pendingCount?
- Can I set a callback when activeCount changes?
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.