Skip to main content
Deno 2 is finally here 🎉️
Learn more
Module

x/proc/legacy/deps.ts>pooledMap

A high-level way to run child processes that is easy, flexible, powerful, and prevents resource leaks.
Go to Latest
function pooledMap
import { pooledMap } from "https://deno.land/x/proc@0.20.22/legacy/deps.ts";

pooledMap transforms values from an (async) iterable into another async iterable. The transforms are done concurrently, with a max concurrency defined by the poolLimit.

If an error is thrown from iterableFn, no new transformations will begin. All currently executing transformations are allowed to finish and still yielded on success. After that, the rejections among them are gathered and thrown by the iterator in an AggregateError.

Examples

Example 1

import { pooledMap } from "https://deno.land/std@0.224.0/async/pool.ts";

const results = pooledMap(
  2,
  [1, 2, 3],
  (i) => new Promise((r) => setTimeout(() => r(i), 1000)),
);

for await (const value of results) {
  // ...
}

Parameters

poolLimit: number

The maximum count of items being processed concurrently.

array: Iterable<T> | AsyncIterable<T>

The input array for mapping.

iteratorFn: (data: T) => Promise<R>

The function to call for every item of the array.

Returns

AsyncIterableIterator<R>