ant-design-vue
Version:
An enterprise-class UI design language and Vue-based implementation
31 lines (26 loc) • 628 B
JavaScript
export function allPromiseFinish(promiseList) {
var hasError = false;
var count = promiseList.length;
var results = [];
if (!promiseList.length) {
return Promise.resolve([]);
}
return new Promise(function (resolve, reject) {
promiseList.forEach(function (promise, index) {
promise.catch(function (e) {
hasError = true;
return e;
}).then(function (result) {
count -= 1;
results[index] = result;
if (count > 0) {
return;
}
if (hasError) {
reject(results);
}
resolve(results);
});
});
});
}