Skip to content

Instantly share code, notes, and snippets.

@seanstrom
Created January 20, 2015 06:08
Show Gist options
  • Save seanstrom/c981dd7447e31b78d37a to your computer and use it in GitHub Desktop.
Save seanstrom/c981dd7447e31b78d37a to your computer and use it in GitHub Desktop.
Async JS/Node - Sequential Async.js Example - Part 1
// Part 1
function findLikesForPostsByUsername(username, mainCallback) {
async.waterfall([
function(callback) {
findUserByUserName(username, callback)
},
function(user, callback) {
findPostsByUser(user, callback)
},
function(posts, callback) {
findLikesByPosts(posts, callback)
},
], function(err, likes) {
if(err) return mainCallback(err)
var totalLikes = likes.reduce(function(x, y) { return x + y })
mainCallback(null, totalLikes)
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment