Skip to content

Instantly share code, notes, and snippets.

@julien-sarazin
Last active March 10, 2016 01:23
Show Gist options
  • Save julien-sarazin/a3704e698f2874d89b45 to your computer and use it in GitHub Desktop.
Save julien-sarazin/a3704e698f2874d89b45 to your computer and use it in GitHub Desktop.
to-beer-ornot-to-beer
function drink(Promise, friend, pints){
var count = 0;
var promises = pints.map(function(pint){
return friend
.drink()
.then(increaseCount)
.catch(reject);
});
return Promise.all(promises)
.then(congrats);
function increaseCount(){
count ++;
}
function reject(){
return Promise.reject('Damn ' + friend.name + '! You stopped after ' + count + ' pints!');
}
function congrats(){
return "Congratulation to " + friend.name + "! You drank " + pints.length + ' pints! Hura!'
}
}
@julien-sarazin
Copy link
Author

@Zae means the function drink you wrote wasn't returning a promise.
@neolectron Totally agree on that, i will next time, thanks for sharing.
@evannieuwburg agree on that too, would be nice. We'll think about it, see if it could be easily integrated for the next release.

Thanks a lot guys for your feedback!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment