UNPKG

ix

Version:

The Interactive Extensions for JavaScript

76 lines (74 loc) 3.28 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.repeat = exports.RepeatAsyncIterable = void 0; const tslib_1 = require("tslib"); const asynciterablex_js_1 = require("../asynciterablex.js"); const withabort_js_1 = require("./withabort.js"); const aborterror_js_1 = require("../../aborterror.js"); /** @ignore */ class RepeatAsyncIterable extends asynciterablex_js_1.AsyncIterableX { constructor(source, count) { super(); this._source = source; this._count = count; } [Symbol.asyncIterator](signal) { return tslib_1.__asyncGenerator(this, arguments, function* _a() { var _b, e_1, _c, _d, _e, e_2, _f, _g; (0, aborterror_js_1.throwIfAborted)(signal); if (this._count === -1) { while (1) { try { for (var _h = true, _j = (e_1 = void 0, tslib_1.__asyncValues((0, withabort_js_1.wrapWithAbort)(this._source, signal))), _k; _k = yield tslib_1.__await(_j.next()), _b = _k.done, !_b; _h = true) { _d = _k.value; _h = false; const item = _d; yield yield tslib_1.__await(item); } } catch (e_1_1) { e_1 = { error: e_1_1 }; } finally { try { if (!_h && !_b && (_c = _j.return)) yield tslib_1.__await(_c.call(_j)); } finally { if (e_1) throw e_1.error; } } } } else { for (let i = 0; i < this._count; i++) { try { for (var _l = true, _m = (e_2 = void 0, tslib_1.__asyncValues((0, withabort_js_1.wrapWithAbort)(this._source, signal))), _o; _o = yield tslib_1.__await(_m.next()), _e = _o.done, !_e; _l = true) { _g = _o.value; _l = false; const item = _g; yield yield tslib_1.__await(item); } } catch (e_2_1) { e_2 = { error: e_2_1 }; } finally { try { if (!_l && !_e && (_f = _m.return)) yield tslib_1.__await(_f.call(_m)); } finally { if (e_2) throw e_2.error; } } } } }); } } exports.RepeatAsyncIterable = RepeatAsyncIterable; /** * Repeats the async-enumerable sequence a specified number of times. * * @template TSource The type of the elements in the source sequence. * @param {number} [count=-1] Number of times to repeat the sequence. If not specified, the sequence repeats indefinitely. * @returns {MonoTypeOperatorAsyncFunction<TSource>} The async-iterable sequence producing the elements of the given sequence repeatedly. */ function repeat(count = -1) { return function repeatOperatorFunction(source) { return new RepeatAsyncIterable(source, count); }; } exports.repeat = repeat; //# sourceMappingURL=repeat.js.map