Last active
February 26, 2020 07:03
-
-
Save giltayar/d2352238ae93c83dcb96a77e8084dc63 to your computer and use it in GitHub Desktop.
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
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