Last active
August 29, 2015 14:13
-
-
Save seanstrom/983034d7ea2894a736b5 to your computer and use it in GitHub Desktop.
Async JS/Node - Sequential Promises Example - Part 1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Part 1 | |
function findLikesForPostsByUsername(username, callback) { | |
var promise = new Promise(function(resolver, rejector) { | |
findUserByUsername(username) | |
.then(findPostsByUser) | |
.then(findLikesByPosts) | |
.then(function(likes) { | |
var totalLikes = likes.reduce(function(x, y) { return x + y }) | |
resolver(totalLikes) | |
}) | |
.catch(function(err) { | |
rejector(err) | |
}) | |
}) | |
return promise | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment