Created
April 13, 2015 13:23
-
-
Save chinmay185/00b76d4aebadacd4e273 to your computer and use it in GitHub Desktop.
missing return breaks the promise chain and causes subtle bugs
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(){ | |
return ["tweet1", "tweet2"]; | |
}); | |
}; | |
getUser("tom") | |
.then(function(user) { | |
getTweets(user) | |
}) | |
.then(function(tweets) { | |
console.log("tweets: ", tweets); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment