I want to use combineLatest to get a bunch of result. Then one of result is passed as input parameter to do another subscribe call.
combineLatest([first, second, third, four, five]).pipe(take(1)).
subscribe(([a, b, c, d, e]) => {
this.showData1(a);
this.showData2(b);
this.showData3(c);
this.showData4(d);
if(e > 8) {
this.myService.updateStatus(e).subscribe(
result => this.setupStatus(result)
);
}
});
The logic is from the 5 results, 4 of them are used for rendering screen. The last one I use it to do a subscribe, its returning result will used some where.
But I feel that it is not right because sometimes it seems this.setupStatus(result) is not running inside the combineLatest. Memory leak?
>Solution :
hard to diagnose why it wouldn’t be running without knowing more about the observables. but I’d do it something like this to avoid nested subscribes and make this a little easier to diagnose / manage:
combineLatest([first, second, third, four, five]).pipe(
take(1),
switchMap(([a, b, c, d, e]) => {
this.showData1(a);
this.showData2(b);
this.showData3(c);
this.showData4(d);
return this.myService.updateStatus(e);
})
).subscribe(result => this.setupStatus(result));
possibly structuring a little differently depending on when exactly I want things to happen.