minor fixes
This commit is contained in:
parent
75302a601e
commit
386870dd50
1 changed files with 15 additions and 1 deletions
|
@ -219,7 +219,7 @@ The first promise here was fastest, so it became the result. After the first set
|
|||
|
||||
## Promise.any
|
||||
|
||||
Similar to `Promise.race`, but waits only for the first fulfilled promise and gets its result. If all of the given promises are rejected, then the returned promise is rejected with [`AggregateError`](mdn:js/AggregateError).
|
||||
Similar to `Promise.race`, but waits only for the first fulfilled promise and gets its result. If all of the given promises are rejected, then the returned promise is rejected with [`AggregateError`](mdn:js/AggregateError) - a special error object that stores all promise errors in its `errors` property.
|
||||
|
||||
The syntax is:
|
||||
|
||||
|
@ -239,6 +239,20 @@ Promise.any([
|
|||
|
||||
The first promise here was fastest, but it was rejected, so the second promise became the result. After the first fulfilled promise "wins the race", all further results are ignored.
|
||||
|
||||
Here's an example when all promises fail:
|
||||
|
||||
```js run
|
||||
Promise.any([
|
||||
new Promise((resolve, reject) => setTimeout(() => reject(new Error("Ouch!")), 1000)),
|
||||
new Promise((resolve, reject) => setTimeout(() => reject(new Error("Error!")), 2000))
|
||||
]).catch(error => {
|
||||
console.log(error.constructor.name); // AggregateError
|
||||
console.log(error.errors[0]); // Error: Ouch!
|
||||
console.log(error.errors[1]); // Error: Error
|
||||
});
|
||||
```
|
||||
|
||||
As you can see, error objects for failed promises are available in the `errors` property of the `AggregateError` object.
|
||||
|
||||
## Promise.resolve/reject
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue