Skip to content

settle

Runs an array of promises concurrently and partitions the outcomes instead of rejecting on the first failure, unlike Promise.all. Built on top of Promise.allSettled, but returns fulfilled values and rejection reasons already split apart so callers don’t need to inspect status themselves.

No concurrency limit, and none is possible here: promises are already-constructed Promise objects, and a promise starts running the moment it’s created — by the time settle receives the array, every promise in it is already in flight. There is nothing left to throttle. If you need to cap how many run at once (e.g. many file reads or requests), use parallelSettle instead, which takes functions (() => Promise<T>) so it controls when each one starts.

Available since v3.0.0

import { settle } from '@helpers4/promise';
// or, from the all-in-one package (same code, one install):
import { settle } from 'helpers4/promise';
settle<T>(promises: readonly Promise<T>[]): Promise<object>
ParameterTypeDescription
promisesreadonly Promise<T>[]Promises to run concurrently

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

Runs promises concurrently and splits results instead of rejecting on the first failure.

const { fulfilled, rejected } = await settle([
  Promise.resolve(1),
  Promise.reject(new Error('boom')),
  Promise.resolve(3),
])
// => { fulfilled: [1, 3], rejected: [Error('boom')] }

Returns an empty rejected array when nothing fails.

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

View source on GitHub