-
-
Save pratyushcrd/7012cacbc00078f3aac31040d77c9a30 to your computer and use it in GitHub Desktop.
callback-hell
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(Error('Store is unavailable'), null) | |
} | |
buyBrownBread(input, (brownBreadErr, brownBreadResponse) => { | |
// if unable to buy brown bread, buy white bread | |
if (brownBreadErr) { | |
buyWhiteBread(input, (whiteBreadErr, whiteBreadResponse) => { | |
if (whiteBreadErr) { | |
return callback(Error('Breads not in stock!'), null) | |
} | |
// success | |
callback(null, whiteBreadResponse) | |
}) | |
} else { | |
// success | |
callback(null, brownBreadResponse) | |
} | |
}) | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment