You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
24 lines
443 B
24 lines
443 B
|
2 years ago
|
"use strict";
|
||
|
|
|
||
|
|
function settle(promises) {
|
||
|
|
const resolutions = [];
|
||
|
|
const rejections = [];
|
||
|
|
|
||
|
|
function resolved(value) {
|
||
|
|
resolutions.push(value);
|
||
|
|
}
|
||
|
|
|
||
|
|
function rejected(error) {
|
||
|
|
rejections.push(error);
|
||
|
|
}
|
||
|
|
|
||
|
|
const wait = Promise.all(promises.map(promise => promise.then(resolved, rejected)));
|
||
|
|
return wait.then(() => {
|
||
|
|
return {
|
||
|
|
successful: resolutions,
|
||
|
|
failed: rejections
|
||
|
|
};
|
||
|
|
});
|
||
|
|
}
|
||
|
|
|
||
|
|
module.exports = settle;
|