look like ninja code
It can be more readable with same line of code. There was a lot of nested parenthesis.
This commit is contained in:
parent
26b393a7d8
commit
a4194ceeff
1 changed files with 8 additions and 9 deletions
|
@ -176,15 +176,14 @@ So for each promise we get its status and `value/error`.
|
||||||
If the browser doesn't support `Promise.allSettled`, it's easy to polyfill:
|
If the browser doesn't support `Promise.allSettled`, it's easy to polyfill:
|
||||||
|
|
||||||
```js
|
```js
|
||||||
if(!Promise.allSettled) {
|
if (!Promise.allSettled) {
|
||||||
Promise.allSettled = function(promises) {
|
const rejectHandler = reason => ({ status: 'rejected', reason });
|
||||||
return Promise.all(promises.map(p => Promise.resolve(p).then(value => ({
|
|
||||||
status: 'fulfilled',
|
const resolveHandler = value => ({ status: 'fulfilled', value });
|
||||||
value
|
|
||||||
}), reason => ({
|
Promise.allSettled = function (promises) {
|
||||||
status: 'rejected',
|
const convertedPromises = promises.map(p => Promise.resolve(p).then(resolveHandler, rejectHandler));
|
||||||
reason
|
return Promise.all(convertedPromises);
|
||||||
}))));
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue