amis-rpc-design/node_modules/rc-field-form/es/utils/asyncUtil.js
2023-10-07 19:42:30 +08:00

26 lines
623 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);
});
});
});
}