Skip to content

Instantly share code, notes, and snippets.

@claustres
Last active February 20, 2018 06:39
Show Gist options
  • Save claustres/bc69a8a6bc4720109a0ea9b3da0b97fd to your computer and use it in GitHub Desktop.
Save claustres/bc69a8a6bc4720109a0ea9b3da0b97fd to your computer and use it in GitHub Desktop.
Async/Await misconception
const delay = (duration) =>
new Promise(resolve => setTimeout(resolve, duration))
async function asyncWithAwait(prefix) {
console.log(prefix + ' before await')
await delay(1000)
console.log(prefix + ' after await')
}
function asyncWithPromise(prefix) {
console.log(prefix + ' before promise')
return delay(1000)
.then(_ => console.log(prefix + ' after promise'))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment