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 6/29/2026
Question
RepoPilot
The pLimit function accepts two types for its concurrency argument:
number— A direct concurrency limit valueobject— An options object with aconcurrencyproperty
This is defined in [index.d.ts:L89], which shows:
export default function pLimit(concurrency: number | Options): LimitFunction;
The Options type is specified in [index.d.ts:L91-L106], where concurrency is a required number property (minimum 1), and there's an optional rejectOnClear boolean property.
The implementation in [index.js:L3-L8] handles both cases:
export default function pLimit(concurrency) {
let rejectOnClear = false;
if (typeof concurrency === 'object') {
({concurrency, rejectOnClear = false} = concurrency);
}
So you can call pLimit(1) with a number, or pLimit({concurrency: 1, rejectOnClear: true}) with an options object.
FOLLOW_UPS:
- How does the concurrency limit affect task execution?
- What happens when clearQueue() is called with rejectOnClear?
- How can you change the concurrency limit after creation?
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.