Skip to content

Instantly share code, notes, and snippets.

@naugtur
Created October 28, 2019 22:02
Show Gist options
  • Save naugtur/491753d6d07ce59b9a397b2491be3b27 to your computer and use it in GitHub Desktop.
Save naugtur/491753d6d07ce59b9a397b2491be3b27 to your computer and use it in GitHub Desktop.
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