commit
fd08e1c20c
1 changed files with 8 additions and 9 deletions
|
@ -177,14 +177,13 @@ If the browser doesn't support `Promise.allSettled`, it's easy to polyfill:
|
||||||
|
|
||||||
```js
|
```js
|
||||||
if (!Promise.allSettled) {
|
if (!Promise.allSettled) {
|
||||||
|
const rejectHandler = reason => ({ status: 'rejected', reason });
|
||||||
|
|
||||||
|
const resolveHandler = value => ({ status: 'fulfilled', value });
|
||||||
|
|
||||||
Promise.allSettled = function (promises) {
|
Promise.allSettled = function (promises) {
|
||||||
return Promise.all(promises.map(p => Promise.resolve(p).then(value => ({
|
const convertedPromises = promises.map(p => Promise.resolve(p).then(resolveHandler, rejectHandler));
|
||||||
status: 'fulfilled',
|
return Promise.all(convertedPromises);
|
||||||
value
|
|
||||||
}), reason => ({
|
|
||||||
status: 'rejected',
|
|
||||||
reason
|
|
||||||
}))));
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue