UNPKG

@reactivex/ix-es5-esm

Version:

The Interactive Extensions for JavaScript

61 lines (59 loc) 2.49 kB
import { __asyncValues, __awaiter, __generator } from "tslib"; import { wrapWithAbort } from './operators/withabort.js'; import { throwIfAborted } from '../aborterror.js'; /** * Converts an existing async-iterable to a promise containing the array of values. * * @template TSource The type of elements in the source sequence. * @param {AsyncIterable<TSource>} source The source sequence to convert to an array. * @param {AbortSignal} [signal] An optional abort signal to cancel the operation at any time. * @returns {Promise<TSource[]>} A promise containing all the items from the source sequence as an array. */ export function toArray(source, signal) { var _a, e_1, _b, _c; return __awaiter(this, void 0, void 0, function () { var results, _d, _e, _f, item, e_1_1; return __generator(this, function (_g) { switch (_g.label) { case 0: throwIfAborted(signal); results = []; _g.label = 1; case 1: _g.trys.push([1, 6, 7, 12]); _d = true, _e = __asyncValues(wrapWithAbort(source, signal)); _g.label = 2; case 2: return [4 /*yield*/, _e.next()]; case 3: if (!(_f = _g.sent(), _a = _f.done, !_a)) return [3 /*break*/, 5]; _c = _f.value; _d = false; item = _c; results.push(item); _g.label = 4; case 4: _d = true; return [3 /*break*/, 2]; case 5: return [3 /*break*/, 12]; case 6: e_1_1 = _g.sent(); e_1 = { error: e_1_1 }; return [3 /*break*/, 12]; case 7: _g.trys.push([7, , 10, 11]); if (!(!_d && !_a && (_b = _e.return))) return [3 /*break*/, 9]; return [4 /*yield*/, _b.call(_e)]; case 8: _g.sent(); _g.label = 9; case 9: return [3 /*break*/, 11]; case 10: if (e_1) throw e_1.error; return [7 /*endfinally*/]; case 11: return [7 /*endfinally*/]; case 12: return [2 /*return*/, results]; } }); }); } //# sourceMappingURL=toarray.js.map