Skip to content

Instantly share code, notes, and snippets.

@giltayar
Last active February 26, 2020 07:03
Show Gist options
  • Save giltayar/d2352238ae93c83dcb96a77e8084dc63 to your computer and use it in GitHub Desktop.
Save giltayar/d2352238ae93c83dcb96a77e8084dc63 to your computer and use it in GitHub Desktop.
const delay = () => new Promise(r => setTimeout(r, 0))
async function returnsPromiseDirectly() {
console.log('returnsPromiseDirectly')
await delay()
// ******* TRY CHANGING THIS:
// With await:
// return await throwsException()
// Without await:
return throwsException()
}
async function throwsException() {
console.log('throwsException')
await delay()
throw new Error('exception')
}
async function main() {
console.log('main')
await delay()
await returnsPromiseDirectly()
}
main().catch(console.error)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment