Last active
August 29, 2015 14:23
-
-
Save joepie91/e13f29d13f517c85d816 to your computer and use it in GitHub Desktop.
Promise flattening
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
doAsyncThing.then(function(result){ | |
return doAnotherAsyncThing().then(function(result){ | |
return doYetAnotherAsyncThing().then(function(result){ | |
console.log("Done!"); | |
}); | |
}); | |
}).catch(function(err){ | |
/* This is where errors from *any* of the above promises end up. */ | |
}); | |
/* ... is functionally the same as ... */ | |
Promise.try(function(){ | |
return doAsyncThing(); | |
}).then(function(result){ | |
return doAnotherAsyncThing(); | |
}).then(function(result){ | |
return doYetAnotherAsyncThing(); | |
}).then(function(result){ | |
console.log("Done!"); | |
}).catch(function(err){ | |
/* This is where errors from *any* of the above promises end up. */ | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment