Skip to content

Instantly share code, notes, and snippets.

@Grantismo
Last active August 29, 2015 14:15
Show Gist options
  • Save Grantismo/e8dc06d51718be0df3bc to your computer and use it in GitHub Desktop.
Save Grantismo/e8dc06d51718be0df3bc to your computer and use it in GitHub Desktop.
//obj1 and obj2 are mongoose models
//Doesn't work
aync.parallel([obj1.save, obj2.save], function(err, results){
//do stuff after both objects save
});
//Works
aync.parallel([obj1.save.bind(obj1), obj2.save.bind(obj2)], function(err, results){
//do stuff after both objects save
});
@niftylettuce
Copy link

async.map([ obj1, obj2 ], function(obj, callback) {
  obj.save(callback)
}, function(err, results) {
  console.log('err', err, 'results', results);
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment