Promises

Promise.any()

ECMAScript API used in Node.js: returns the first successful result while ignoring earlier rejections until all inputs have failed. All failures produce AggregateError, including for an empty iterable. Use this for interchangeable read-only candidates only when duplicated work is acceptable; it does not cancel other inputs. Tested on Node.js 22.16.0. Example output (one line per entry): ["backup", "AggregateError a,b"].

Formal Syntax & Structure

nodejs syntaxnodejs
Promise.any(iterable)

Parameters & Attributes

NameTypeDescription
iterableIterableCandidate values or promises.

Return Value

Promise

First fulfillment or AggregateError rejection.

Working Example

Example Snippetnodejs
console.log(await Promise.any([Promise.reject(new Error('offline')), Promise.resolve('backup')]));try {    await Promise.any([Promise.reject('a'), Promise.reject('b')]);}catch (error) {    console.log(error.name, error.errors.join(','));}
Node.js Reference