Skip to main content
Home
This release is 6 versions behind 1.0.16 — the latest version of @std/async. Jump to latest

@std/async@1.0.10
Built and signed on GitHub Actions

Utilities for asynchronous operations, like delays, debouncing, or pooling

This package works with Cloudflare Workers, Node.js, Deno, Bun, Browsers
This package works with Cloudflare Workers
This package works with Node.js
This package works with Deno
This package works with Bun
This package works with Browsers
JSR Score
100%
Published
11 months ago (1.0.10)
function pooledMap
pooledMap<
T,
R,
>
(
poolLimit: number,
array: Iterable<T> | AsyncIterable<T>,
iteratorFn: (data: T) => Promise<R>,
): AsyncIterableIterator<R>

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

Usage

import { pooledMap } from "@std/async/pool";
import { assertEquals } from "@std/assert";

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

assertEquals(await Array.fromAsync(results), [1, 2, 3]);

Type Parameters

the input type.

the output type.

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.

Return Type

AsyncIterableIterator<R>

The async iterator with the transformed values.

New Ticket: Report package

Please provide a reason for reporting this package. We will review your report and take appropriate action.

Please review the JSR usage policy before submitting a report.

Add Package

deno add jsr:@std/async

Import symbol

import { pooledMap } from "@std/async";
or

Import directly with a jsr specifier

import { pooledMap } from "jsr:@std/async";

Add Package

pnpm i jsr:@std/async
or (using pnpm 10.8 or older)
pnpm dlx jsr add @std/async

Import symbol

import { pooledMap } from "@std/async";

Add Package

yarn add jsr:@std/async
or (using Yarn 4.8 or older)
yarn dlx jsr add @std/async

Import symbol

import { pooledMap } from "@std/async";

Add Package

vlt install jsr:@std/async

Import symbol

import { pooledMap } from "@std/async";

Add Package

npx jsr add @std/async

Import symbol

import { pooledMap } from "@std/async";

Add Package

bunx jsr add @std/async

Import symbol

import { pooledMap } from "@std/async";