Dealing with multiple asynchronous calls can be tricky, especially when you need to wait for all of them to finish before moving on to the next step. In my case, I have separate calls that may or may not be made depending on user input. How can I efficiently handle this situation?
submitButton_Clicked() {
this.busy = this.service.call1() // must be called
.first().subscribe(
if (success){
// **Logic to decide if call 2 is needed**
...
this.busy = this.service.call2() // might be called
.first().subscribe();
// **Logic to decide if call 3 is needed**
...
this.busy = this.service.call3() // might be called
.first().subscribe();
this.router('route'); // should route after all potential calls
}
);
}
As I'm still learning about observables, I'm a bit unsure about the best approach to solve this. Any guidance would be greatly appreciated. Thank you!