mirror of
https://gitee.com/ant-design-vue/ant-design-vue.git
synced 2024-12-15 17:31:43 +08:00
33 lines
646 B
JavaScript
33 lines
646 B
JavaScript
export function allPromiseFinish(promiseList) {
|
|
let hasError = false;
|
|
let count = promiseList.length;
|
|
const results = [];
|
|
|
|
if (!promiseList.length) {
|
|
return Promise.resolve([]);
|
|
}
|
|
|
|
return new Promise((resolve, reject) => {
|
|
promiseList.forEach((promise, index) => {
|
|
promise
|
|
.catch(e => {
|
|
hasError = true;
|
|
return e;
|
|
})
|
|
.then(result => {
|
|
count -= 1;
|
|
results[index] = result;
|
|
|
|
if (count > 0) {
|
|
return;
|
|
}
|
|
|
|
if (hasError) {
|
|
reject(results);
|
|
}
|
|
resolve(results);
|
|
});
|
|
});
|
|
});
|
|
}
|