Skip to content

Instantly share code, notes, and snippets.

@mafintosh
Last active March 30, 2022 06:30
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save mafintosh/d18db4daea7910c16137a053b3b513b1 to your computer and use it in GitHub Desktop.
Save mafintosh/d18db4daea7910c16137a053b3b513b1 to your computer and use it in GitHub Desktop.
promise-unhandled-why.js
start()
async function start () {
const promises = [
new Promise((resolve, reject) => setTimeout(reject, 1000)),
Promise.reject(),
Promise.reject()
]
for (const a of promises) {
try {
await a
} catch {
console.log('failed, continuing')
}
}
}
@vikasg603
Copy link

And 1 thing, I also noticed.
Your unhandled promise will be gone after 1 sec.
I assumed that after 1 sec, for loop handling them (1 sec for timeout).
So as soon as they got handler, unhandled promise gone.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment