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/1/2026
The pLimit function expects the concurrency argument to be either a number or an object.
According to the type definitions in [index.d.ts:L89], the function signature is:
export default function pLimit(concurrency: number | Options): LimitFunction;
When passing a number, it directly sets the concurrency limit. When passing an object, it should be of type Options [index.d.ts:L91-L104], which has:
concurrency(required): anumberwith a minimum of1rejectOnClear(optional): aboolean, defaults tofalse
The implementation validates this in the pLimit function [index.js:L3-L10]. If an object is passed, it destructures the concurrency and rejectOnClear properties, then calls validateConcurrency(concurrency) [index.js:L123-L126] to ensure the concurrency value is an integer greater than 0 (or Number.POSITIVE_INFINITY).
FOLLOW_UPS:
- What happens if concurrency validation fails?
- How does rejectOnClear affect clearQueue behavior?
- Can you modify concurrency after creating a limit?
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.