I have found the following use case while working with promises. I am writing CoffeeScript for concision but the reading for JavaScript developers should be straight forwards
getUserName().then (userName) ->
getRelatedCompany(userName).then (relatedCompany) ->
registerConnexion(userName, relatedCompany)
In the above all request depend of the above results of the previous ones. What's the proper way to solve this to get something like this:
getUserName().then (userName) ->
getRelatedCompany(userName)
.then (relatedCompany) ->
# in that example, userName would be undefined here but there's less callbackception
registerConnexion(userName, relatedCompany)
EDIT: I am using bluebird as promise library.