We intend to implement and ship Promise.any, a proposed way to `await`
several promises and continue as soon as any of them becomes
fulfilled. André Bargull [:anba] has contributed patches implementing
this feature. It will land in Nightly soon.

We'll ship it once we're confident the specification is stable
(Promise.any is at Stage 3 in the TC39 Process[1], but some minor
changes are still in flight).

Bug: https://bugzilla.mozilla.org/show_bug.cgi?id=1568903

Proposed standard: https://tc39.es/proposal-promise-any/

Proposal repository: https://github.com/tc39/proposal-promise-any/

MDN:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/any

Platform coverage: All, Nightly only, no pref

DevTools bug: N/A

Other browsers: Not implementing yet, as far as I can tell. I expect V8
will start soon and JSC will implement it eventually.

Polyfills are already available for this proposal[2][3].

Testing: The patch[4] contains tests, including tests for aspects of
behavior that we do not expect test262 to test thoroughly: error stacks
and cross-realm behavior. Test262 will eventually provide independent
tests.

Use cases: Promise.any is similar to Promise.race. It's for cases in
async code when you would use Promise.race, but you're interested in the
first success, not the first failure. If you were implementing something
like Gecko's "Race Cache With Network" behavior[5][6], you might write:

```js
let response = await Promise.any([network_fetch, cache_fetch]);
```

    [1]: https://tc39.es/process-document/
    [2]: https://github.com/zloirock/core-js#promiseany
    [3]: https://github.com/es-shims/Promise.any#promiseany-
    [4]: https://phabricator.services.mozilla.com/D51659
    [5]:
https://groups.google.com/forum/#!topic/mozilla.dev.platform/fvCmc6kR9Uk
    [6]: about:networking#rcwn

-j
_______________________________________________
dev-platform mailing list
dev-platform@lists.mozilla.org
https://lists.mozilla.org/listinfo/dev-platform

Reply via email to