RepoPilot

What types does the main pLimit function expect for its concurrency argument?

About sindresorhus/p-limit · 2 messages · last activity 5/18/2026

Question

What types does the main pLimit function expect for its concurrency argument?

RepoPilot

The pLimit function accepts the concurrency argument as either a number or an object.

Number: A positive integer representing the concurrency limit. According to the validation logic in [index.js:L123-L128], the value must be an integer greater than 0, or Number.POSITIVE_INFINITY.

Object: An options object with a concurrency property. The type definition for this is Options, which is defined in [index.d.ts:L91-L102] as:

export type Options = {
	readonly concurrency: number;
	readonly rejectOnClear?: boolean;
};

This is shown in the main function signature at [index.d.ts:L89]:

export default function pLimit(concurrency: number | Options): LimitFunction;

The implementation in [index.js:L3-L8] handles both cases—if concurrency is an object, it destructures the concurrency and optional rejectOnClear properties from it.

FOLLOW_UPS:

  • What happens if you pass invalid concurrency values?
  • How does the rejectOnClear option affect clearQueue behavior?
  • Can you change concurrency after creating the limit function?

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.