| 1 |
import { EMPTY } from '../observable/empty'; |
| 2 |
import { operate } from '../util/lift'; |
| 3 |
import { createOperatorSubscriber } from './OperatorSubscriber'; |
| 4 |
import { innerFrom } from '../observable/innerFrom'; |
| 5 |
import { timer } from '../observable/timer'; |
| 6 |
export function repeat(countOrConfig) { |
| 7 |
var _a; |
| 8 |
var count = Infinity; |
| 9 |
var delay; |
| 10 |
if (countOrConfig != null) { |
| 11 |
if (typeof countOrConfig === 'object') { |
| 12 |
(_a = countOrConfig.count, count = _a === void 0 ? Infinity : _a, delay = countOrConfig.delay); |
| 13 |
} |
| 14 |
else { |
| 15 |
count = countOrConfig; |
| 16 |
} |
| 17 |
} |
| 18 |
return count <= 0 |
| 19 |
? function () { return EMPTY; } |
| 20 |
: operate(function (source, subscriber) { |
| 21 |
var soFar = 0; |
| 22 |
var sourceSub; |
| 23 |
var resubscribe = function () { |
| 24 |
sourceSub === null || sourceSub === void 0 ? void 0 : sourceSub.unsubscribe(); |
| 25 |
sourceSub = null; |
| 26 |
if (delay != null) { |
| 27 |
var notifier = typeof delay === 'number' ? timer(delay) : innerFrom(delay(soFar)); |
| 28 |
var notifierSubscriber_1 = createOperatorSubscriber(subscriber, function () { |
| 29 |
notifierSubscriber_1.unsubscribe(); |
| 30 |
subscribeToSource(); |
| 31 |
}); |
| 32 |
notifier.subscribe(notifierSubscriber_1); |
| 33 |
} |
| 34 |
else { |
| 35 |
subscribeToSource(); |
| 36 |
} |
| 37 |
}; |
| 38 |
var subscribeToSource = function () { |
| 39 |
var syncUnsub = false; |
| 40 |
sourceSub = source.subscribe(createOperatorSubscriber(subscriber, undefined, function () { |
| 41 |
if (++soFar < count) { |
| 42 |
if (sourceSub) { |
| 43 |
resubscribe(); |
| 44 |
} |
| 45 |
else { |
| 46 |
syncUnsub = true; |
| 47 |
} |
| 48 |
} |
| 49 |
else { |
| 50 |
subscriber.complete(); |
| 51 |
} |
| 52 |
})); |
| 53 |
if (syncUnsub) { |
| 54 |
resubscribe(); |
| 55 |
} |
| 56 |
}; |
| 57 |
subscribeToSource(); |
| 58 |
}); |
| 59 |
} |
| 60 |
//# sourceMappingURL=repeat.js.map |