What types does the main pLimit function expect for its concurrency argument?
What types does the main pLimit function expect for its concurrency argument?
About sindresorhus/p-limit · 2 messages · last activity 7/6/2026
Question
RepoPilot
The pLimit function accepts two types for its concurrency argument:
number— A direct concurrency limit value (minimum: 1)object— An options object with aconcurrencyproperty and optionalrejectOnClearboolean
According to [index.d.ts:L89], the function signature is:
export default function pLimit(concurrency: number | Options): LimitFunction;
Where the Options type [index.d.ts:L91-L109] defines:
concurrency(required):number— minimum 1rejectOnClear(optional):boolean— defaults tofalse
In the implementation [index.js:L3-L10], the function handles both cases by checking if the argument is an object and destructuring accordingly:
if (typeof concurrency === 'object') {
({concurrency, rejectOnClear = false} = concurrency);
}
So you can pass either pLimit(1) for a simple concurrency limit, or pLimit({concurrency: 1, rejectOnClear: true}) for more control over behavior.
FOLLOW_UPS:
- How does the validation work for concurrency values?
- What happens when rejectOnClear is enabled?
- How do activeCount and pendingCount differ?
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.