UNPKG

rxjs

Version:

Reactive Extensions for modern JavaScript

37 lines 1.35 kB
import { EMPTY } from '../observable/empty'; import { operate } from '../util/lift'; import { OperatorSubscriber } from './OperatorSubscriber'; export function repeat(count) { if (count === void 0) { count = Infinity; } return count <= 0 ? function () { return EMPTY; } : operate(function (source, subscriber) { var soFar = 0; var innerSub; var subscribeForRepeat = function () { var syncUnsub = false; innerSub = source.subscribe(new OperatorSubscriber(subscriber, undefined, function () { if (++soFar < count) { if (innerSub) { innerSub.unsubscribe(); innerSub = null; subscribeForRepeat(); } else { syncUnsub = true; } } else { subscriber.complete(); } })); if (syncUnsub) { innerSub.unsubscribe(); innerSub = null; subscribeForRepeat(); } }; subscribeForRepeat(); }); } //# sourceMappingURL=repeat.js.map