Skip to content

Instantly share code, notes, and snippets.

@AMEYCHAVAN
Created July 24, 2015 13:26
Show Gist options
  • Save AMEYCHAVAN/3b833903795248738c76 to your computer and use it in GitHub Desktop.
Save AMEYCHAVAN/3b833903795248738c76 to your computer and use it in GitHub Desktop.
multile promises for loop nodejs
function get_all_the_things(things) {
var the_promises = [];
things.forEach(function(thing) {
var deferred = Q.defer();
get_a_thing(thing, function(result) {
deferred.resolve(result);
});
the_promises.push(deferred.promise);
});
return Q.all(the_promises);
}
//===========================================
//this is how u call
get_all_the_things(filesattachment) //[{gridfsid:1},{gridfsid:2}]
.then(function(result) {
// $.debug('\n\n')
})
.done();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment