-
-
Save joepie91/7d22af310ef68de4f507 to your computer and use it in GitHub Desktop.
Nested scopes in promises
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
/* Follow-up from https://gist.github.com/joepie91/211c8e99fb5a83b76079, which shows promise flattening */ | |
Promise.try(function(){ | |
return outerThingOne(); | |
}).then(function(value){ | |
return Promise.try(function(){ | |
return innerThingOne(); | |
}).then(function(subValue){ | |
/* We're using both `value` AND `subValue` here! Both are in scope, because we're nesting. */ | |
return innerThingTwo(value, 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