Skip to content

Instantly share code, notes, and snippets.

@joepie91
Last active August 29, 2015 14:23
Show Gist options
  • Save joepie91/e13f29d13f517c85d816 to your computer and use it in GitHub Desktop.
Save joepie91/e13f29d13f517c85d816 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