Rxjs Chain Observables Completing At Any Point
Is there any way to chain several observables but allowing the chain to complete at any time? I have three Observables, they all return booleans. However, I would only want to prog
Solution 1:
You can setup an observable that control the flow and complete it when you are done. Also use zip operator - it will complete the whole flow if one of the observable(in our case the control one) is completed.
let control$ = new Rx.Subject();
let data$ = Rx.Observable.interval()
.map(x => x<10?true:false)
.do(flag => {
if(flag) control$.next(true);
else control$.complete();
});
Rx.Observable.zip(data$.filter(x=>x), control$.startWith(true), (x,y)=>x)
.subscribe(x=>console.log(x))
Post a Comment for "Rxjs Chain Observables Completing At Any Point"