title: Wait for subscription in the same function
body: <p>I would like to know how I can wait in an If-Else-branch for all REST-calls to finish, even though the Else-side has no REST calls.</p>
  <p>Here's an example:</p>
  <pre><code>createNewList(oldList: any[]) {
   const newList = [];
   oldList.forEach(element =&gt; {
     if (element.isAwesome) {
       this.RESTCall().subscribe(result =&gt; {
         element.property = result;
         newList.push(element);
       });
     } else {
      newList.push(element);
     }
   });
  
   // wait here for all elements of RESTCall, then:
   return newList;
  }
  </code></pre>
  <p>I hope you can follow me.
  In the current version, of course, the restcalls take much longer and the function transfers the list too early.</p>
  <p>My first approach would be to add different, higher-level observables to a list, merge them via mergeAll (<a href="https://www.learnrxjs.io/learn-rxjs/operators/combination/mergeall" rel="nofollow noreferrer">https://www.learnrxjs.io/learn-rxjs/operators/combination/mergeall</a>) and then execute this complete() function. But that seems very tortuous to me.</p>
  <p>Do you have any tips or processes for me to solve something like this in an easier way?</p>