Is there a way to make an If-Else branch wait for all REST calls to finish, even if the Else side has no REST calls? Let's take a look at this scenario:
createNewList(oldList: any[]) {
const newList = [];
oldList.forEach(element => {
if (element.isAwesome) {
this.RESTCall().subscribe(result => {
element.property = result;
newList.push(element);
});
} else {
newList.push(element);
}
});
// need to wait here for all RESTCall elements before proceeding:
return newList;
}
Your input on this matter would be greatly appreciated. Currently, with the restcalls taking longer, the function is transferring the list too early.
One solution could involve adding higher-level observables to a list, merging them with mergeAll (https://www.learnrxjs.io/learn-rxjs/operators/combination/mergeall), and then executing the complete() function. However, this approach seems overly complicated.
Do you have any insights or suggestions on how to simplify this process?