Skip to content

Instantly share code, notes, and snippets.

@pratyushcrd
Last active April 8, 2019 21:39
Show Gist options
  • Save pratyushcrd/ac3d7c9fc810c8210865f487cc67b7b6 to your computer and use it in GitHub Desktop.
Save pratyushcrd/ac3d7c9fc810c8210865f487cc67b7b6 to your computer and use it in GitHub Desktop.
An example to show nested callback's complexity
function buyBread (input, callback) {
gotoStore(input, (storeErr, storeResponse) => {
if (storeErr) {
return callback(storeErr, null)
}
buyBrownBread(input, (brownBreadErr, brownBreadResponse) => {
if (brownBreadErr) {
buyWhiteBread(input, (whiteBreadErr, whiteBreadResponse) => {
if (whiteBreadErr) {
return callback(whiteBreadErr, null)
}
callback(null, whiteBreadResponse)
})
} else {
callback(null, brownBreadResponse)
}
})
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment