Created
October 11, 2022 19:24
-
-
Save connoro7/dd550f259a75d9b4d088f0b6bdabe60d to your computer and use it in GitHub Desktop.
How-to and How-to-not Async Await
This file contains 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
async function mainBadTiming() { | |
setTimeout(() => { | |
console.log('hello') | |
}, 1000) | |
console.log('world') | |
} | |
console.log(mainBadTiming()); | |
async function mainWaitForTimeout() { | |
await new Promise((resolve) => { | |
setTimeout(() => { | |
console.log('hello') | |
resolve() | |
}, 1000) | |
}) | |
console.log('world') | |
} | |
console.log(mainWaitForTimeout()) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment