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.

Available since next

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