Skip to content

Instantly share code, notes, and snippets.

@dd701116
Last active March 28, 2021 22:46
Show Gist options
  • Save dd701116/8f4f2648fb0eecb3e08416aa403b9b24 to your computer and use it in GitHub Desktop.
Save dd701116/8f4f2648fb0eecb3e08416aa403b9b24 to your computer and use it in GitHub Desktop.
// An asynchronous function
async function theAsynchronousMethod() {
return Math.floor(Math.random() * Math.floor(6));
}
// Another asynchronous function
async function anotherAsynchronousMethod() {
// Wait the response
let dice = await theAsynchronousMethod();
// And continue
if (dice>=3) {
console.log("Yes, I'll do it !");
}else{
throw new Error("Nope, drop it !");
}
}
try{
anotherAsynchronousMethod();
} catch (e) {
console.error(e.message);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment