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 5/25/2026
Question
RepoPilot
The pLimit function accepts two types for its concurrency argument:
number— a numeric concurrency limit (minimum 1, can beNumber.POSITIVE_INFINITY)object— an options object with aconcurrencyproperty and optionalrejectOnClearboolean
This is shown in the TypeScript definition [index.d.ts:L89] where the function signature is:
export default function pLimit(concurrency: number | Options): LimitFunction;
The Options type is defined in [index.d.ts:L91-L107] with:
concurrency: number(required, minimum 1)rejectOnClear?: boolean(optional, defaults to false)
In the implementation [index.js:L3-L7], the function handles both forms:
let rejectOnClear = false;
if (typeof concurrency === 'object') {
({concurrency, rejectOnClear = false} = concurrency);
}
The validateConcurrency function [index.js:L123-L126] ensures the concurrency value is a positive integer or Number.POSITIVE_INFINITY.
FOLLOW_UPS:
- What happens if you pass invalid concurrency values?
- Can you change the concurrency limit after creating a limiter?
- How does the rejectOnClear option affect pending promises?
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.