Skip to content

Instantly share code, notes, and snippets.

@nem035
Created October 6, 2018 06:54
Show Gist options
  • Select an option

  • Save nem035/5d7174fcd2847d57c2f5dfc4a3fc6f97 to your computer and use it in GitHub Desktop.

Select an option

Save nem035/5d7174fcd2847d57c2f5dfc4a3fc6f97 to your computer and use it in GitHub Desktop.
// 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