Last active
April 8, 2019 21:39
-
-
Save pratyushcrd/ac3d7c9fc810c8210865f487cc67b7b6 to your computer and use it in GitHub Desktop.
An example to show nested callback's complexity
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
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