| 1 |
import { innerFrom } from '../observable/innerFrom'; |
| 2 |
import { Subject } from '../Subject'; |
| 3 |
import { operate } from '../util/lift'; |
| 4 |
import { createOperatorSubscriber } from './OperatorSubscriber'; |
| 5 |
export function repeatWhen(notifier) { |
| 6 |
return operate(function (source, subscriber) { |
| 7 |
var innerSub; |
| 8 |
var syncResub = false; |
| 9 |
var completions$; |
| 10 |
var isNotifierComplete = false; |
| 11 |
var isMainComplete = false; |
| 12 |
var checkComplete = function () { return isMainComplete && isNotifierComplete && (subscriber.complete(), true); }; |
| 13 |
var getCompletionSubject = function () { |
| 14 |
if (!completions$) { |
| 15 |
completions$ = new Subject(); |
| 16 |
innerFrom(notifier(completions$)).subscribe(createOperatorSubscriber(subscriber, function () { |
| 17 |
if (innerSub) { |
| 18 |
subscribeForRepeatWhen(); |
| 19 |
} |
| 20 |
else { |
| 21 |
syncResub = true; |
| 22 |
} |
| 23 |
}, function () { |
| 24 |
isNotifierComplete = true; |
| 25 |
checkComplete(); |
| 26 |
})); |
| 27 |
} |
| 28 |
return completions$; |
| 29 |
}; |
| 30 |
var subscribeForRepeatWhen = function () { |
| 31 |
isMainComplete = false; |
| 32 |
innerSub = source.subscribe(createOperatorSubscriber(subscriber, undefined, function () { |
| 33 |
isMainComplete = true; |
| 34 |
!checkComplete() && getCompletionSubject().next(); |
| 35 |
})); |
| 36 |
if (syncResub) { |
| 37 |
innerSub.unsubscribe(); |
| 38 |
innerSub = null; |
| 39 |
syncResub = false; |
| 40 |
subscribeForRepeatWhen(); |
| 41 |
} |
| 42 |
}; |
| 43 |
subscribeForRepeatWhen(); |
| 44 |
}); |
| 45 |
} |
| 46 |
//# sourceMappingURL=repeatWhen.js.map |