Question
How can I check the current number of active tasks?
About sindresorhus/p-limit · 2 messages · last activity 7/6/2026
How can I check the current number of active tasks?
You can check the current number of active tasks using the limit.activeCount property. This returns the number of promises that are currently running.
Here's how to use it:
import pLimit from 'p-limit';
const limit = pLimit(5);
// After queuing some tasks...
console.log(limit.activeCount); // Number of promises currently running
A practical example from the recipes is monitoring progress while work is running [recipes.md:L191-L214]:
const progressInterval = setInterval(() => {
console.log(`Running: ${limit.activeCount}, pending: ${limit.pendingCount}`);
}, 250);
This allows you to track both active tasks and pending tasks (those waiting to run) at any time.
FOLLOW_UPS:
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.