Last active
March 30, 2022 06:30
-
-
Save mafintosh/d18db4daea7910c16137a053b3b513b1 to your computer and use it in GitHub Desktop.
promise-unhandled-why.js
This file contains hidden or 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
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') | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.