title: Wait for all promises to resolve
body: <p>So I have a situation where I have multiple promise chains of an unknown length. I want some action to run when all the CHAINS have been processed. Is that even possible? Here is an example:</p>
  
  <pre><code>app.controller('MainCtrl', function($scope, $q, $timeout) {
      var one = $q.defer();
      var two = $q.defer();
      var three = $q.defer();
  
      var all = $q.all([one.promise, two.promise, three.promise]);
      all.then(allSuccess);
  
      function success(data) {
          console.log(data);
          return data + "Chained";
      }
  
      function allSuccess(){
          console.log("ALL PROMISES RESOLVED")
      }
  
      one.promise.then(success).then(success);
      two.promise.then(success);
      three.promise.then(success).then(success).then(success);
  
      $timeout(function () {
          one.resolve("one done");
      }, Math.random() * 1000);
  
      $timeout(function () {
          two.resolve("two done");
      }, Math.random() * 1000);
  
      $timeout(function () {
          three.resolve("three done");
      }, Math.random() * 1000);
  });
  </code></pre>
  
  <p>In this example, I set up a <code>$q.all()</code> for promises one, two, and three which will get resolved at some random time. I then add promises onto the ends of one and three. I want the <code>all</code> to resolve when all the chains have been resolved. Here is the output when I run this code:</p>
  
  <pre><code>one done 
  one doneChained
  two done
  three done
  ALL PROMISES RESOLVED
  three doneChained
  three doneChainedChained 
  </code></pre>
  
  <p>Is there a way to wait for the chains to resolve?</p>