Created
October 6, 2018 06:54
-
-
Save nem035/5d7174fcd2847d57c2f5dfc4a3fc6f97 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| // nesting promises is an anti-pattern | |
| // as with callbacks, we end up with a | |
| // "pyramid of doom" | |
| function getThing(arg) { | |
| return new Promise(function (resolve, reject) { | |
| getStuff(arg) | |
| .then(function (stuff) { | |
| getMoreStuff(stuff) | |
| .then(function (moreStuff) { | |
| getThatFinalThing(moreStuff) | |
| .then(function (thing) { | |
| resolve(thing) | |
| }, reject) | |
| }, reject) | |
| }, reject) | |
| }) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment