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) { |
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) |
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 showFavouriteArticles () { | |
getUser() | |
.then(user => getFavouriteArticles(user)) | |
.then(articles => showArticles(articles)) | |
.catch(err => notifyError(err)) | |
} |
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) { | |
return gotoStore(input) | |
.then(() => { | |
return buyBrownBread(input) | |
.catch(() => buyWhiteBread(input)) | |
}) | |
} |
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 readFile(path) { | |
return new Promise((resolve, reject) => { | |
fs.readFile(path, (err, data) => { | |
if (err) { | |
return reject(err) | |
} | |
return resolve(data) | |
}) | |
}) | |
} |
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
module.exports = { | |
/** | |
* Function to verify all validations | |
* @param {...any} paramsRaw An array of validation results, | |
* Values can either be `true` or `error string`. | |
*/ | |
all: async function (...paramsRaw) { | |
const params = await Promise.all(paramsRaw) | |
const error = params | |
.filter(val => typeof val === 'string')[0] |
OlderNewer