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.
Heres the pseudo 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){ ... });
but I can't put my finger on how to get them all to resolve correctly and returns the results in one array.
tracer(myArr)even have.then? In this code, you're not returning a promise to use.thenon.