What you could to is, instead of working with Observables here, work with Promises as they can be combined with async/await which allows a synchronous code flow.
public async overallMasterFunction(){
executeMemberSetup();
let price = await calculatePriceAPI(); // Wait for this API line to complete, and conduct further steps
let totalAmount = price * this.quantity;
console.log('Sales Completed')
}
calculatePriceAPI(): Promise<any> {
return this.customerSalesProxy.getPrice().toPromise();
}
Pay attention to the async in the method signature which signals that this function does do asynchronous communication and allows to use the await keyword within. Await will make sure the Promise is resolved before going to the next line. This should feel very natural again as it is basically synchronous code now.
However, in most cases you should be fine without async/await and make full usage of Obserables and asynchronous communication in general.
Find an example below:
public overallMasterFunction(){
executeMemberSetup();
let price = calculatePriceAPI().subscribe(price => {
let totalAmount = price * this.quantity;
console.log('Sales Completed')
});
}
calculatePriceAPI(): Observable<any> {
this.customerSalesProxy.getPrice();
}
From your API, simply return the Observable so that your code can react upon it with it sown subscribe. Then, within that subscribe you can use the price and log something to console once everything is finished.