Created
March 24, 2019 04:50
-
-
Save maksbd19/0ee777b1096fd747dfdb745ac2731a8c to your computer and use it in GitHub Desktop.
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://stackoverflow.com/questions/55320737/how-to-wait-for-a-promise-to-resolve-or-reject-then-move-to-next-command#55320737 | |
// your original code | |
const validatePreconditions = ({ exitOnFailure = true } = {}) => { | |
let portSuccess = true | |
checkIfPortIsAvailable(3000).then((val) => portSuccess = val , (err) => console.log("DEBUG1:",err)) | |
console.log("DEBUG2:",portSuccess) | |
if (! portSuccess && exitOnFailure) { | |
logger.error(colors.red('Exiting due to unsatisfied precondition!')) | |
process.exit(1) | |
} | |
return portSuccess | |
} | |
// the async/await pattent | |
const validatePreconditions = async ({ exitOnFailure = true } = {}) => { | |
let portSuccess = true; | |
try{ | |
portSuccess = await checkIfPortIsAvailable(3000); | |
} | |
catch(err){ | |
portSuccess = false; | |
console.log("DEBUG1:",err); | |
} | |
console.log("DEBUG2:",portSuccess) | |
if (! portSuccess && exitOnFailure) { | |
logger.error(colors.red('Exiting due to unsatisfied precondition!')) | |
process.exit(1) | |
} | |
return portSuccess; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment