ix
Version:
The Interactive Extensions for JavaScript
71 lines (69 loc) • 2.96 kB
JavaScript
import { __asyncGenerator, __asyncValues, __await } from "tslib";
import { AsyncIterableX } from '../asynciterablex.mjs';
import { wrapWithAbort } from './withabort.mjs';
import { throwIfAborted } from '../../aborterror.mjs';
/** @ignore */
export class RepeatAsyncIterable extends AsyncIterableX {
constructor(source, count) {
super();
this._source = source;
this._count = count;
}
[Symbol.asyncIterator](signal) {
return __asyncGenerator(this, arguments, function* _a() {
var _b, e_1, _c, _d, _e, e_2, _f, _g;
throwIfAborted(signal);
if (this._count === -1) {
while (1) {
try {
for (var _h = true, _j = (e_1 = void 0, __asyncValues(wrapWithAbort(this._source, signal))), _k; _k = yield __await(_j.next()), _b = _k.done, !_b; _h = true) {
_d = _k.value;
_h = false;
const item = _d;
yield yield __await(item);
}
}
catch (e_1_1) { e_1 = { error: e_1_1 }; }
finally {
try {
if (!_h && !_b && (_c = _j.return)) yield __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, __asyncValues(wrapWithAbort(this._source, signal))), _o; _o = yield __await(_m.next()), _e = _o.done, !_e; _l = true) {
_g = _o.value;
_l = false;
const item = _g;
yield yield __await(item);
}
}
catch (e_2_1) { e_2 = { error: e_2_1 }; }
finally {
try {
if (!_l && !_e && (_f = _m.return)) yield __await(_f.call(_m));
}
finally { if (e_2) throw e_2.error; }
}
}
}
});
}
}
/**
* 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.
*/
export function repeat(count = -1) {
return function repeatOperatorFunction(source) {
return new RepeatAsyncIterable(source, count);
};
}
//# sourceMappingURL=repeat.mjs.map