Skip to content

parallelSettle

Runs an array of async functions with a concurrency limit, partitioning the outcomes instead of rejecting on the first failure — parallel with settle’s fulfilled/rejected split.

Takes functions (not already-created promises, unlike settle) so it controls when each one starts: that’s what makes the concurrency limit meaningful. At most concurrency functions run at any time; as soon as one settles, the next queued function starts.

Available since v3.0.2

import { parallelSettle } from '@helpers4/promise';
// or, from the all-in-one package (same code, one install):
import { parallelSettle } from 'helpers4/promise';
parallelSettle<T>(functions: readonly function[], concurrency: number): Promise<object>
ParameterTypeDescription
functionsreadonly function[]Array of functions that return promises
concurrencynumberMaximum number of concurrent executions. `Infinity` means no cap; any other non-finite or non-positive value (`NaN`, `0`, negative) is clamped to `1` (fully sequential) rather than rejected.

Promise<object> — An object with fulfilled values and rejected reasons, each in input order

Limit concurrency without one failure stopping the rest

Section titled “Limit concurrency without one failure stopping the rest”

Runs at most concurrency functions at a time and partitions outcomes instead of rejecting on the first failure.

const { fulfilled, rejected } = await parallelSettle(
  [() => fetch('/a'), () => fetch('/b'), () => fetch('/c')],
  2
)
// At most 2 requests run at a time; a failing request doesn't stop the others

Returns an empty rejected array when nothing fails.

const { fulfilled, rejected } = await parallelSettle(
  [() => Promise.resolve('a'), () => Promise.resolve('b')],
  2
)
// => { fulfilled: ['a', 'b'], rejected: [] }

View source on GitHub