Skip to content

Instantly share code, notes, and snippets.

@royhowie
Last active June 14, 2016 04:19
Show Gist options
  • Save royhowie/d26813b8628cf993676088cfeac9c49e to your computer and use it in GitHub Desktop.
Save royhowie/d26813b8628cf993676088cfeac9c49e to your computer and use it in GitHub Desktop.
avoiding the pyramid of doom
// http://stackoverflow.com/questions/37801654/how-to-know-when-all-promises-are-resolved-in-a-dynamic-iterable-parameter
function userLogIn () {
return $http.get('/login/user/password')
.then(data => data.loggedOk ? $http.get('/checkIfIsAdmin') : Promise.reject())
.then(data => data.isAdmin ? $http.get('/getUserName') : Promise.reject())
.then(data => data.hasUserName ? $http.get('/getDate') : Promise.reject())
}
userLogIn().then(() => {
// everything worked
}, () => {
// was rejected somewhere along the line
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment