Skip to content

Instantly share code, notes, and snippets.

@joepie91
Created July 19, 2015 03:35
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save joepie91/211c8e99fb5a83b76079 to your computer and use it in GitHub Desktop.
Save joepie91/211c8e99fb5a83b76079 to your computer and use it in GitHub Desktop.
Promise flattening
Promise.try(function(){
return outerThingOne();
}).then(function(value){
return Promise.try(function(){
return innerThingOne();
}).then(function(subValue){
return innerThingTwo(subValue);
});
}).then(function(result){
return outerThingThree(result);
});
/* ... is equivalent to ... */
Promise.try(function(){
return outerThingOne();
}).then(function(value){
return innerThingOne();
}).then(function(subValue){
return innerThingTwo(subValue);
}).then(function(result){
return outerThingThree(result);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment