wishthis/node_modules/rxjs/dist/esm5/internal/operators/repeatWhen.js

45 lines
1.7 KiB
JavaScript
Raw Normal View History

2022-04-07 07:06:43 +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();
notifier(completions$).subscribe(createOperatorSubscriber(subscriber, function () {
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