Skip to content

Instantly share code, notes, and snippets.

@ptasker
Last active August 29, 2015 14:20
Show Gist options
  • Save ptasker/9a5f736a3a3a24ed3719 to your computer and use it in GitHub Desktop.
Save ptasker/9a5f736a3a3a24ed3719 to your computer and use it in GitHub Desktop.
NodeJS promises issue
function authenticate() {
return getUsername()
.then(function (username) {
return getUser(username);
})
// chained because we will not need the user name in the next event
.then(function (user) {
return getPassword()
// nested because we need both user and password next
.then(function (password) {
if (user.passwordHash !== hash(password)) {
throw new Error("Can't authenticate");
}
});
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment