Created
January 8, 2019 13:50
-
-
Save pqt/883216dfe290585ac4b839f8209949b7 to your computer and use it in GitHub Desktop.
Callback Hell, Promise Chains & Async/Await - Inspired by this gif: https://media.discordapp.net/attachments/244238416248569857/489901409907769344/js-callbacks-promises-asyncawait.gif
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
// https://i.imgur.com/V0PNlIZ.png | |
(async () => { | |
const a = await getData(); | |
const b = await getMoreData(a); | |
const c = await getMoreData(b); | |
const d = await getMoreData(c); | |
const e = await getMoreData(d); | |
console.log(e) | |
})(); |
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
// https://i.imgur.com/3vrblsw.png | |
getData(a => { | |
getMoreData(a, b => { | |
getMoreData(b, c => { | |
getMoreData(c, d => { | |
getMoreData(d, e => { | |
console.log(e) | |
}) | |
}) | |
}) | |
}) | |
}) |
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
// https://i.imgur.com/rxyblDT.png | |
getData() | |
.then(a => getMoreData(a)) | |
.then(b => getMoreData(b)) | |
.then(c => getMoreData(c)) | |
.then(d => getMoreData(d)) | |
.then(e => console.log(e)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment