JSFiddle - React, Tailwind, and code Playground
HTML
<script src="https://cdnjs.cloudflare.com/ajax/libs/rxjs/5.5.2/Rx.min.js"></script>
JavaScript
var Observable = Rx.Observable;
var initialDelay = 2000;
var repeatDelay = 1000;
function repeat(v) {
return v;
}
function init() {
return Observable.of(42);
}
function status(_) {
return Observable.create(function(observer) {
observer.next(!!Math.round(Math.random()));
observer.complete();
});
}
const last_value$ = new Rx.BehaviorSubject(null);
const delayed$ = init()
.delay(initialDelay)
.flatMap(id =>
status(id).repeatWhen(completions =>
completions.delay(repeatDelay)
.takeWhile(_ => repeat(last_value$.getValue()))
)
).share();
delayed$.subscribe(last_value$);
delayed$.subscribe(console.log);