Skip to content

Instantly share code, notes, and snippets.

@itsananderson
Created June 23, 2015 20:51
Show Gist options
  • Save itsananderson/6a22ebb6d8524e75084f to your computer and use it in GitHub Desktop.
Save itsananderson/6a22ebb6d8524e75084f to your computer and use it in GitHub Desktop.
Storing state at the top-level scope to be shared between promise handlers.
var user;
var balance;
getCurrentUser()
.then(function (currentUser) {
user = currentUser;
return getBalance(user);
})
.then(function (userBalance) {
balance = userBalance;
return deposit(user, 123);
})
.then(function (newBalance) {
console.log("Deposit for user " + user.name + " old balance: " + balance + " new balance: " + newBalance);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment