I understand that there are lot of questions on the title's subject but I wasn't able to find clear and concise question/response that would help me with following.
Assume we have x amount of web api calls that return observables Observable<cs[]>... See
init() {
this.service.serviceA().subscribe({
next: (as) => {
this.as = as;
this.service.serviceB().subscribe({
next: (bs) => {
this.bs = bs;
this.service.serviceC().subscribe({
next: (cs) => {
this.cs = cs;
this.restructureABCs();
},
error: (e) => this.notification.showError('Failed to load cs! Error: ' + e.messageerror)
});
},
error: (e) => this.notification.showError('Failed to load bs! Error: ' + e.messageerror)
});
},
error: (e) => this.notification.showError('Failed to load as! Error: ' + e.messageerror)
})
}
Function restructureABCs() depends on as/bs & cs. as, bs & cs don't depend on each other. Current implementation is ugly and can be improved but I'm not sure which operator I should use. It doesn't make sense to me to use concatMap as (according to my possibly flawed understanding) multiple streams are going to be merged into one, which I don't want. All I need is to make sure that as/bs & cs are loaded before restructureABCs() function is invoked.
Angular13, rxjs7.4
If BS, CS, AS don't depend on each other, they can run parallel, all you need is make sure all of this Observables complete to run restructureABCs(). So you can use combineLatest/forkJoin for this case.