title: Angular2 Observable - Await multiple function calls before proceeding
body: <p>I am trying to improve my knowledge of Angular2 by migrating an application currently written in Angular1/AngularJS.</p>
  <p>One feature in particular has me stumped. I am trying to replicate a feature where a calling function waits to proceed until the function it is calling has completed a loop of promises. In AngularJS, the function I am calling looks basically like this:</p>
  <pre><code>this.processStuff = function( inputarray, parentnodeid ) {
      var promises = [];
      var _self = this;
      angular.forEach( inputarray , function( nodeid ) {
  
          switch ( parentnodeid )
          {
              case ‘AAA’ : var component = _self.doMoreStuff( nodeid, parentnodeid ); break;
              case ‘BBB’ : var component = _self.doMoreStuff( nodeid, parentnodeid ); break;
              case ‘CCC’ : var component = _self.doMoreStuff( nodeid, parentnodeid ); break;
              default    : var component = null;
          }
          promises.push( component );
      });
      return $q.all(promises);
  }; 
  </code></pre>
  <p>It contains a <code>forEach</code> loop that calls another function (<code>doMoreStuff</code>) that also returns a promise, and it stores all those returned promises in an array.</p>
  <p>With AngularJS, when I call <code>processStuff</code> in another function, I could count on the system waiting until <code>processStuff</code> completed before entering into the code in the then block:</p>
  <pre><code>service.processStuff( arraying, parentidarg )
         .then(function( data ) {
                ... 
  </code></pre>
  <p>The caller of <code>processStuff</code> waits for all <code>doMoreStuff</code> invocations to complete until the caller of <code>processStuff</code> enters into its <code>then</code> block.</p>
  <p>I am unsure of how to achieve this with Angular2 and Observables. I can see from these posts that to mimic promises, Observables basically just use <code>subscribe()</code> instead of <code>then()</code>:</p>
  <p><a href="https://stackoverflow.com/questions/34436429/angular-1-x-q-to-angular-2-0-beta">Angular 1.x $q to Angular 2.0 beta</a></p>
  <p>But how do I await all invocations in the <code>forEach</code> loop to complete before my application can proceed?</p>