Skip to content

Function: pLimit()

ts
function pLimit(concurrency): LimitFunction;

Creates a concurrency limiter that allows at most concurrency promises to run simultaneously. 创建一个并发限制器,最多同时运行 concurrency 个 Promise。

Parameters

ParameterType
concurrencynumber

Returns

LimitFunction

Example

ts
const limit = pLimit(2)
const results = await Promise.all([1, 2, 3].map((n) => limit(() => Promise.resolve(n * 2))))
results // => [2, 4, 6]

Since

1.0.0

Released under the MIT License.