Skip to content

concurrentPool() function

根据给定的并发任务数确保并发级别的一致性。

Signature:

typescript
declare function concurrentPool<A>(
  length: number,
  iterable: AsyncIterable<A>,
): AsyncIterableIterator<A>;

Example

ts
await pipe(
  [1, 2, 3, 4, 5, 6],
  toAsync,
  map((a) => delay(100 * a, a)),
  concurrentPool(3),
  each(console.log), // log 1, 2, 3, 4, 5, 6
); // 0.9 seconds

Open Source Code

Released under the Apache-2.0 License.