ECMAScript proposal: Promise.any
Branch: master
Clone or download
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.editorconfig Initial commit Jan 30, 2019
.gitignore Add placeholder spec Jan 30, 2019
.nvmrc Initial commit Jan 30, 2019
.travis-github-deploy-key.enc Set up auto-deploy Jan 30, 2019
.travis.yml Set up auto-deploy Jan 30, 2019
README.md Present combinators as a table Jan 30, 2019
package.json Initial commit Jan 30, 2019
spec.html Add placeholder spec Jan 30, 2019

README.md

ECMAScript proposal: Promise.any

Status

This proposal is at stage 0 of the TC39 process.

Motivation

There are four main combinators in the Promise landscape.

name description
Promise.allSettled does not short-circuit separate proposal 🔜
Promise.all short-circuits when an input value is rejected added in ES2015
Promise.race short-circuits when an input value is settled added in ES2015
Promise.any short-circuits when an input value is fulfilled this proposal 🆕

These are all commonly available in userland promise libraries, and they’re all independently useful, each one serving different use cases.

Proposed solution

Promise.any accepts an array of promises and returns a promise that is fulfilled by the first given promise to be fulfilled, or rejected with an array of rejection reasons if all of the given promises are rejected.

High-level API

try {
  const first = await Promise.any(promises);
  // Any of the promises was fulfilled.
} catch (reasons) {
  // All of the promises were rejected.
}

Or, without async/await:

Promise.any(promises).then(
  (first) => {
    // Any of the promises was fulfilled.
  },
  (reasons) => {
    // All of the promises were rejected.
    // `reasons` is an array containing the rejection reasons.
  }
);

FAQ

Why choose the name any?

It clearly describes what it does, and there’s precedent for the name any in userland libraries offering this functionality:

Illustrative examples

TODO

TC39 meeting notes

  • TODO

Specification

Implementations

  • none yet