Last active
March 10, 2016 01:23
-
-
Save julien-sarazin/a3704e698f2874d89b45 to your computer and use it in GitHub Desktop.
to-beer-ornot-to-beer
This file contains hidden or 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
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!' | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@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!