Skip to content

Commit a4194ce

Browse files
authored
look like ninja code
It can be more readable with same line of code. There was a lot of nested parenthesis.
1 parent 26b393a commit a4194ce

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

1-js/11-async/05-promise-api/article.md

+8-9
Original file line numberDiff line numberDiff line change
@@ -176,15 +176,14 @@ So for each promise we get its status and `value/error`.
176176
If the browser doesn't support `Promise.allSettled`, it's easy to polyfill:
177177
178178
```js
179-
if(!Promise.allSettled) {
180-
Promise.allSettled = function(promises) {
181-
return Promise.all(promises.map(p => Promise.resolve(p).then(value => ({
182-
status: 'fulfilled',
183-
value
184-
}), reason => ({
185-
status: 'rejected',
186-
reason
187-
}))));
179+
if (!Promise.allSettled) {
180+
const rejectHandler = reason => ({ status: 'rejected', reason });
181+
182+
const resolveHandler = value => ({ status: 'fulfilled', value });
183+
184+
Promise.allSettled = function (promises) {
185+
const convertedPromises = promises.map(p => Promise.resolve(p).then(resolveHandler, rejectHandler));
186+
return Promise.all(convertedPromises);
188187
};
189188
}
190189
```

0 commit comments

Comments
 (0)