2023-02-08 12:35:10 +00:00
|
|
|
import { innerFrom } from '../observable/innerFrom';
|
2022-06-08 10:36:39 +00:00
|
|
|
import { Subject } from '../Subject';
|
|
|
|
import { operate } from '../util/lift';
|
|
|
|
import { createOperatorSubscriber } from './OperatorSubscriber';
|
|
|
|
export function repeatWhen(notifier) {
|
|
|
|
return operate(function (source, subscriber) {
|
|
|
|
var innerSub;
|
|
|
|
var syncResub = false;
|
|
|
|
var completions$;
|
|
|
|
var isNotifierComplete = false;
|
|
|
|
var isMainComplete = false;
|
|
|
|
var checkComplete = function () { return isMainComplete && isNotifierComplete && (subscriber.complete(), true); };
|
|
|
|
var getCompletionSubject = function () {
|
|
|
|
if (!completions$) {
|
|
|
|
completions$ = new Subject();
|
2023-02-08 12:35:10 +00:00
|
|
|
innerFrom(notifier(completions$)).subscribe(createOperatorSubscriber(subscriber, function () {
|
2022-06-08 10:36:39 +00:00
|
|
|
if (innerSub) {
|
|
|
|
subscribeForRepeatWhen();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
syncResub = true;
|
|
|
|
}
|
|
|
|
}, function () {
|
|
|
|
isNotifierComplete = true;
|
|
|
|
checkComplete();
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
return completions$;
|
|
|
|
};
|
|
|
|
var subscribeForRepeatWhen = function () {
|
|
|
|
isMainComplete = false;
|
|
|
|
innerSub = source.subscribe(createOperatorSubscriber(subscriber, undefined, function () {
|
|
|
|
isMainComplete = true;
|
|
|
|
!checkComplete() && getCompletionSubject().next();
|
|
|
|
}));
|
|
|
|
if (syncResub) {
|
|
|
|
innerSub.unsubscribe();
|
|
|
|
innerSub = null;
|
|
|
|
syncResub = false;
|
|
|
|
subscribeForRepeatWhen();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
subscribeForRepeatWhen();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
//# sourceMappingURL=repeatWhen.js.map
|