Posted by Arjun Arjun on Friday 24th July 2020, 1 minute read

Javascript - Promise.any

Promise.any is a promise combinator that resolves the resulting promise as soon as one of the input promises is fulfilled.

const promises = [
  fetch('/endpoint-a').then(() => 'a'),
  fetch('/endpoint-b').then(() => 'b'),
  fetch('/endpoint-c').then(() => 'c'),
try {
  const first = await Promise.any(promises);
  // Any of the promises was fulfilled.
  // → e.g. 'b'
} catch (error) {
  // All of the promises were rejected.
  console.assert(error instanceof AggregateError);
  // Log the rejection values:

If all input promises are rejected, the resulting promise is rejected with an AggregateError object containing an error property that holds an array of rejection values.


I am Arjun from Hyderabad (India). I have been working as a software engineer from the last 7+ years, and it is my passion to learn new things and implement them as a practice. Aside from work, I like gardening and spending time with pets.