UNPKG

@reactivex/ix-es5-esm

Version:

The Interactive Extensions for JavaScript

61 lines (59 loc) 2.48 kB
import { __asyncValues, __awaiter, __generator } from "tslib"; import { wrapWithAbort } from './operators/withabort.js'; import { throwIfAborted } from '../aborterror.js'; /** * Converts the existing async-iterable into a promise which resolves a Set. * * @template TSource The type of elements in the source sequence. * @param {AsyncIterable<TSource>} source The async-iterable to convert into a set. * @param {AbortSignal} [signal] An optional abort signal to cancel the operation at any time. * @returns {Promise<Set<TSource>>} A promise which contains a Set with all the elements from the async-iterable. */ export function toSet(source, signal) { var _a, e_1, _b, _c; return __awaiter(this, void 0, void 0, function () { var set, _d, _e, _f, item, e_1_1; return __generator(this, function (_g) { switch (_g.label) { case 0: throwIfAborted(signal); set = new Set(); _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; set.add(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*/, set]; } }); }); } //# sourceMappingURL=toset.js.map