Function: pLimit()
ts
function pLimit(concurrency): LimitFunction;Creates a concurrency limiter that allows at most concurrency promises to run simultaneously. 创建一个并发限制器,最多同时运行 concurrency 个 Promise。
Parameters
| Parameter | Type |
|---|---|
concurrency | number |
Returns
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