RepoPilot

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

About sindresorhus/p-limit · 2 messages · last activity 7/13/2026

Question

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

RepoPilot

Based on the repository data, the pLimit function accepts the following types for its concurrency argument:

  1. A number — an integer value representing the concurrency limit (minimum of 1, or Number.POSITIVE_INFINITY)
  2. An options object — with a concurrency property and an optional rejectOnClear property

From the TypeScript definitions [index.d.ts:L89-L90], the signature is:

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

Where Options is defined as [index.d.ts:L91-L132]:

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

In the implementation [index.js:L3-L8], you can see the function handles both cases:

export default function pLimit(concurrency) {
	let rejectOnClear = false;

	if (typeof concurrency === 'object') {
		({concurrency, rejectOnClear = false} = concurrency);
	}

The validation function [index.js:L123-L128] enforces that concurrency must be a positive integer or Number.POSITIVE_INFINITY:

function validateConcurrency(concurrency) {
	if (!((Number.isInteger(concurrency) || concurrency === Number.POSITIVE_INFINITY) && concurrency > 0)) {
		throw new TypeError('Expected `concurrency` to be a number from 1 and up');
	}
}

FOLLOW_UPS:

  • What happens when you call clearQueue with rejectOnClear?
  • How does the concurrency property get dynamically adjusted?
  • What is the purpose of the activeCount property?

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.