Util.js 950 B

1234567891011121314151617181920212223242526
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.allSettledWithThrow = void 0;
  4. /**
  5. * Like `Promise.allSettled()` but throws an error if any promises are rejected.
  6. */
  7. const allSettledWithThrow = async (promises) => {
  8. const results = await Promise.allSettled(promises);
  9. const rejected = results.filter((result) => result.status === 'rejected');
  10. if (rejected.length) {
  11. for (const result of rejected) {
  12. console.error(result.reason);
  13. }
  14. throw new Error(`${rejected.length} promise(s) failed - see the above errors`);
  15. }
  16. // Note: TS was complaining about using `.filter().map()` here for some reason
  17. const values = [];
  18. for (const result of results) {
  19. if (result.status === 'fulfilled') {
  20. values.push(result.value);
  21. }
  22. }
  23. return values;
  24. };
  25. exports.allSettledWithThrow = allSettledWithThrow;
  26. //# sourceMappingURL=Util.js.map