Skip to content

mapWithLimit

mapWithLimit<T, R>(items, concurrency, fn): Promise<R[]>

Defined in: packages/synapse-core/src/utils/concurrency.ts:63

Like Promise.all(items.map(fn)), but runs at most concurrency calls at a time.

Type Parameter
T
R
Parameter Type Description
items readonly T[] The inputs.
concurrency number The maximum number of concurrent calls.
fn (item, index) => Promise<R> The async work per item.

Promise<R[]>

The results, in input order.

import { mapWithLimit } from '@filoz/synapse-core/utils'

const pieces = await mapWithLimit(dataSets, 4, (dataSet) => loadPieces(dataSet))