Skip to content

Instantly share code, notes, and snippets.

@timoxley
Forked from mafintosh/promise-unhandled-why.js
Last active July 13, 2021 17:03
Show Gist options
  • Save timoxley/1b35188417a493866062aad33123a02a to your computer and use it in GitHub Desktop.
Save timoxley/1b35188417a493866062aad33123a02a 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(0), 1000)),
Promise.reject(1),
Promise.reject(2)
]
promises.forEach(p => p.catch(() => {})) // prevent unhandled
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