asyncUtil.js 741 B

1234567891011121314151617181920212223242526272829303132
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.allPromiseFinish = allPromiseFinish;
  6. function allPromiseFinish(promiseList) {
  7. var hasError = false;
  8. var count = promiseList.length;
  9. var results = [];
  10. if (!promiseList.length) {
  11. return Promise.resolve([]);
  12. }
  13. return new Promise(function (resolve, reject) {
  14. promiseList.forEach(function (promise, index) {
  15. promise.catch(function (e) {
  16. hasError = true;
  17. return e;
  18. }).then(function (result) {
  19. count -= 1;
  20. results[index] = result;
  21. if (count > 0) {
  22. return;
  23. }
  24. if (hasError) {
  25. reject(results);
  26. }
  27. resolve(results);
  28. });
  29. });
  30. });
  31. }