UNPKG

@reactivex/ix-es2015-cjs

Version:

The Interactive Extensions for JavaScript

46 lines (44 loc) 1.75 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.repeatValue = exports.RepeatValueAsyncIterable = void 0; const tslib_1 = require("tslib"); const asynciterablex_js_1 = require("./asynciterablex.js"); const aborterror_js_1 = require("../aborterror.js"); /** @ignore */ class RepeatValueAsyncIterable extends asynciterablex_js_1.AsyncIterableX { constructor(value, count) { super(); this._value = value; this._count = count; } [Symbol.asyncIterator](signal) { return tslib_1.__asyncGenerator(this, arguments, function* _a() { if (this._count === -1) { while (1) { (0, aborterror_js_1.throwIfAborted)(signal); yield yield tslib_1.__await(this._value); } } else { for (let i = 0; i < this._count; i++) { (0, aborterror_js_1.throwIfAborted)(signal); yield yield tslib_1.__await(this._value); } } }); } } exports.RepeatValueAsyncIterable = RepeatValueAsyncIterable; /** * Repeats a given value for the specified number of times as an async-iterable. * * @template TSource The type of element to repeat. * @param {TSource} value The value to repeat as an async-iterable. * @param {number} [count=-1] The number of times to repeat the value, infinite if not specified. * @returns {AsyncIterableX<TSource>} An async-iterable with a single item that is repeated over the specified times. */ function repeatValue(value, count = -1) { return new RepeatValueAsyncIterable(value, count); } exports.repeatValue = repeatValue; //# sourceMappingURL=repeatvalue.js.map