File tree Expand file tree Collapse file tree 1 file changed +8
-9
lines changed
1-js/11-async/05-promise-api Expand file tree Collapse file tree 1 file changed +8
-9
lines changed Original file line number Diff line number Diff line change @@ -176,15 +176,14 @@ So for each promise we get its status and `value/error`.
176176If 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```
You can’t perform that action at this time.
0 commit comments