RepoPilot

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

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

Question

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

RepoPilot

The pLimit function accepts two types for its concurrency argument:

  1. number — a numeric concurrency limit (minimum 1, can be Number.POSITIVE_INFINITY)
  2. object — an options object with a concurrency property and optional rejectOnClear boolean

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.