Skip to content

Instantly share code, notes, and snippets.

@connoro7
Created October 11, 2022 19:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save connoro7/dd550f259a75d9b4d088f0b6bdabe60d to your computer and use it in GitHub Desktop.
Save connoro7/dd550f259a75d9b4d088f0b6bdabe60d to your computer and use it in GitHub Desktop.
How-to and How-to-not Async Await
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