Skip to content

Instantly share code, notes, and snippets.

@wonderdogone
Forked from joepie91/flattening.js
Last active August 29, 2015 14:28
Show Gist options
  • Save wonderdogone/3c53cf3b236f274b7659 to your computer and use it in GitHub Desktop.
Save wonderdogone/3c53cf3b236f274b7659 to your computer and use it in GitHub Desktop.
Promise flattening
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