Wait for the Fastest JavaScript Promise to Be Fulfilled with Promise.any()
lessonDuration 7m 9s
The `Promise.any()` method accepts an array (or any other iterable) of promises as a parameter. It returns a `Promise` object that is fulfilled with the value of the first input promise to fulfill: - As soon as any input promise is fulfilled, the returned `Promise` object is fulfilled with that value. - If all input promises are rejected, the returned `Promise` object is rejected with an `AggregateError` which has an `errors` property containing an array of all rejection reasons. `Promise.any()` can be used to race multiple promises against each other and find the first promise to be fulfilled. **Please note** that at the moment, the Promise.any() method is only implemented in Firefox Nightly. Make sure to use a polyfill in your application to make it work across browsers.