Skip to content

Instantly share code, notes, and snippets.

@fredrick
Created February 1, 2012 02:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fredrick/1714667 to your computer and use it in GitHub Desktop.
Save fredrick/1714667 to your computer and use it in GitHub Desktop.
Async.js and Node.js
var async = require('async');
// Waterfall through callbacks using Mongoose to query for a user
async.waterfall([
function(callback) {
/** Function 1. Find User.
* Pass `user` to Function 2.
*/
User.findOne({ username: 'fred' }, function(error, user) {
if (error) throw error;
callback(error, user);
});
},
/** Function 2. Receive User.
* Pass `user` to final function
*/
function(user, callback) {
callback(user);
}
], function(user) {
// Final function
console.log(user);
});
@cavery8989
Copy link

Thanks

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