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.
34 lines
735 B
34 lines
735 B
import { FieldError } from '../interface';
|
|
export function allPromiseFinish(promiseList: Promise<FieldError>[]): Promise<FieldError[]> {
|
|
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);
|
|
});
|
|
});
|
|
});
|
|
}
|