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 9/1/2026
You can check the current number of active tasks using the activeCount property on the limit function.
[index.d.ts:L2-L4] defines activeCount as:
The number of promises that are currently running.
Here's how to use it:
import pLimit from 'p-limit';
const limit = pLimit(5);
// After you've called limit() with some functions...
console.log(limit.activeCount); // Shows how many promises are currently executing
This is useful for monitoring progress. For example, [recipes.md:L191-L214] shows a practical pattern where you can report progress using both activeCount and pendingCount:
const progressInterval = setInterval(() => {
console.log(`Running: ${limit.activeCount}, pending: ${limit.pendingCount}`);
}, 250);
activeCount is read-only and reflects the real-time number of promises that have started execution but haven't completed yet.
FOLLOW_UPS:
- What's the difference between activeCount and pendingCount?
- How do I monitor progress during concurrent operations?
- Can I dynamically change the concurrency limit?
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.