1234567891011121314151617181920212223242526 |
- 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);
- });
- });
- });
- }
|