Skip to content

Instantly share code, notes, and snippets.

@maksbd19
Created March 24, 2019 04:50
Show Gist options
  • Save maksbd19/0ee777b1096fd747dfdb745ac2731a8c to your computer and use it in GitHub Desktop.
Save maksbd19/0ee777b1096fd747dfdb745ac2731a8c to your computer and use it in GitHub Desktop.
// 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