Last active
May 25, 2019 12:47
-
-
Save irridescentrambler/e455992f9716a6bab893b822d6a82ff4 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
// 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