Created
October 28, 2019 22:02
-
-
Save naugtur/491753d6d07ce59b9a397b2491be3b27 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 asyncOk = async () => { | |
return new Promise(re => setTimeout(re, 0)) | |
} | |
const asyncFail = async () => { | |
return new Promise((_, re) => setTimeout(() => re(Error()), 0)) | |
} | |
const run1 = async () => { | |
try { | |
const [a, b] = [asyncFail(), asyncOk()] | |
console.log(await a, await b) | |
} catch (e) { | |
console.error(e) | |
} | |
} | |
run1() // catches error | |
const run2 = async () => { | |
try { | |
const [a, b] = [asyncFail(), asyncFail()] | |
console.log(await a, await b) | |
} catch (e) { | |
console.error(e) | |
} | |
} | |
run2() // triggers unhandledRejection |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment