title: Recursive Async Looping in NodeJS
body: <p>I'm trying to do a recursive async loop to trace all the children of a particular object from a third-party lib in nodejs.</p>
  
  <p>Heres the pseudo code:</p>
  
  <pre><code>var tracer = function(nodes){
    var promises [];
  
    nodes.forEach(function(node){
  
      // trace returns a promise ...
      var promise = builder.trace(node)
      promises.push(promise);
  
      promise.then(function(tree){
  
        // if we had children, get those
        if(tree.children.length){
          promises.push.apply(promises, tracer(tree.children));
        }
      });   
  
    });
  
    return promises;
  };
  
  RSVP.all(tracer(myArr)).then(function(allTrees){ ... });
  </code></pre>
  
  <p>but I can't put my finger on how to get them all to resolve correctly and returns the results in one array.</p>