combinator

Promise.any

Resolves with the value of the first promise to fulfill, ignoring any rejections until a success occurs. If every promise rejects, it rejects with an AggregateError whose .errors array contains each reason.

Promise.any(iterable)

Parameters

Parameter Purpose
iterable Iterable of promises or values
first fulfillment wins Rejections are ignored while any promise is still pending
AggregateError Thrown when ALL inputs reject; err.errors is the reason array

Examples

const first = await Promise.any([
  fetch('https://a.example/data'),
  fetch('https://b.example/data'),
  fetch('https://c.example/data')
]);

Returns the first mirror that succeeds, tolerating failures from the others.

try {
  await Promise.any([Promise.reject('x'), Promise.reject('y')]);
} catch (e) {
  console.log(e instanceof AggregateError, e.errors); // true, ['x','y']
}

Every promise rejected — you get an AggregateError with all reasons.

await Promise.any([]); // rejects with AggregateError (no promises to succeed)

An empty iterable rejects immediately.

Gotcha

Opposite of Promise.race — rejections do NOT short-circuit. ES2021+ only; check runtime support before relying on AggregateError.

Related

← All JS Promise reference · async/await vs promises vs callbacks