Skip to content

Instantly share code, notes, and snippets.

@irridescentrambler
Last active May 25, 2019 12:47
Show Gist options
  • Save irridescentrambler/e455992f9716a6bab893b822d6a82ff4 to your computer and use it in GitHub Desktop.
Save irridescentrambler/e455992f9716a6bab893b822d6a82ff4 to your computer and use it in GitHub Desktop.
// Just a normal function, not an async function.
function firstFunction(){
return new Promise((resolve, reject)=> {
var randomNumber = (Math.floor(Math.random() * 100) % 2);
if(randomNumber === 0){
setTimeout(() => {
resolve("Number is even");
}, 3000);
}else {
setTimeout(() => {
reject("Number is odd");
}, 4000);
}
});
}
// Async function starts with async keyword.
async function myFirstAsyncFunction(){
const result = await firstFunction();
console.log(result);
}
myFirstAsyncFunction();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment