Skip to content

Instantly share code, notes, and snippets.

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