Last active
June 14, 2016 04:19
-
-
Save royhowie/d26813b8628cf993676088cfeac9c49e to your computer and use it in GitHub Desktop.
avoiding the pyramid of doom
This file contains 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
// 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