This file contains 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
var q = require("q"); | |
var getUser = function(username) { | |
return q.delay(500).then(function(){ | |
return username + " user"; | |
}); | |
}; | |
var getTweets = function(user) { | |
return q.delay(500).then(function(){ |
This file contains 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
var q = require("q"); | |
// v1 | |
q.all([getUser(username1), getUser(username2)]) | |
.then(function(users) { | |
makeFriends(users[0], users[1]); | |
}); | |
// v2 (even better) | |
q.all([fetchUser(username1), fetchUser(username2)]) |
This file contains 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
fetchUser(username1) | |
.then(function(user1) { | |
fetchUser(username2) | |
.then(function(user2) { | |
makeFriends(user1, user2); | |
}); | |
}); |
This file contains 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
getUser("tom") | |
.then(getTweets) | |
.then(updateTimeline) | |
.then(function(){ | |
console.log("done"); | |
}); |
This file contains 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
getUser("tom").then(function(user) { | |
getTweets(user).then(function(tweets) { | |
updateTimeline(tweets) | |
.then(function() { | |
console.log("done"); | |
}); | |
}); | |
}); |
NewerOlder