File tree 1 file changed +8
-9
lines changed
1-js/11-async/05-promise-api
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`.
176
176
If the browser doesn't support `Promise.allSettled`, it's easy to polyfill:
177
177
178
178
```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);
188
187
};
189
188
}
190
189
```
You can’t perform that action at this time.
0 commit comments