rxjs
Version:
Reactive Extensions for modern JavaScript
41 lines • 1.51 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.repeat = void 0;
var empty_1 = require("../observable/empty");
var lift_1 = require("../util/lift");
var OperatorSubscriber_1 = require("./OperatorSubscriber");
function repeat(count) {
if (count === void 0) { count = Infinity; }
return count <= 0
? function () { return empty_1.EMPTY; }
: lift_1.operate(function (source, subscriber) {
var soFar = 0;
var innerSub;
var subscribeForRepeat = function () {
var syncUnsub = false;
innerSub = source.subscribe(new OperatorSubscriber_1.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();
});
}
exports.repeat = repeat;
//# sourceMappingURL=repeat.js.map
;