I am getting a bunch of failed API calls in the network tab in chrome. This is because I can see on the waterfall that my "create customer" subscription hasn't finished its execution yet, then "create address" and "create contact phone number" both run and don't wait for it to finish.
I have looked for answers using the await....toPromise() function, but that is now deprecated and doesn't work in my scenario.
How would I implement this in newer versions of rxjs/angular?
// API call for create customer
this.userService.createCustomer(customer).subscribe({
next: (customerResult: Customer) => {
const createContactAddress =
customerAddress !== undefined
? this.userService.createContactAddress(
customerResult.partyNumber,
customerAddress.toJson()
)
: of(undefined);
const createContactEmail =
email !== undefined
? this.userService.createContactPhoneEmail(
customerResult.partyNumber,
email
)
: of(undefined);
const createContactPhoneNumber =
phone !== undefined
? this.userService.createContactPhoneEmail(
customerResult.partyNumber,
phone
)
: of(undefined);
createContactAddress
.pipe(combineLatestWith(createContactEmail, createContactPhoneNumber))
.subscribe({
next: () => {
this.isSaving = false;
this.modalSaved.emit(customerResult);
},
error: () => {
this.isSaving = false;
this.closeModal();
}
});
},
error: () => {
this.isSaving = false;
this.closeModal();
}
});
}