UNPKG

@reactivex/ix-es2015-cjs

Version:

The Interactive Extensions for JavaScript

41 lines (39 loc) 1.55 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.toSet = void 0; const tslib_1 = require("tslib"); const withabort_js_1 = require("./operators/withabort.js"); const aborterror_js_1 = require("../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. */ function toSet(source, signal) { var _a, e_1, _b, _c; return tslib_1.__awaiter(this, void 0, void 0, function* () { (0, aborterror_js_1.throwIfAborted)(signal); const set = new Set(); try { for (var _d = true, _e = tslib_1.__asyncValues((0, withabort_js_1.wrapWithAbort)(source, signal)), _f; _f = yield _e.next(), _a = _f.done, !_a; _d = true) { _c = _f.value; _d = false; const item = _c; set.add(item); } } catch (e_1_1) { e_1 = { error: e_1_1 }; } finally { try { if (!_d && !_a && (_b = _e.return)) yield _b.call(_e); } finally { if (e_1) throw e_1.error; } } return set; }); } exports.toSet = toSet; //# sourceMappingURL=toset.js.map