Catch errors in worker

This commit is contained in:
Jon Staab
2024-10-14 13:08:21 -07:00
parent c7816120b7
commit df0ad3e7f2
+10 -2
View File
@@ -25,14 +25,22 @@ export class Worker<T> {
this.buffer.push(message)
} else {
for (const handler of this.handlers.get(ANY) || []) {
await handler(message)
try {
await handler(message)
} catch (e) {
console.error(e)
}
}
if (this.opts.getKey) {
const k = this.opts.getKey(message)
for (const handler of this.handlers.get(k) || []) {
await handler(message)
try {
await handler(message)
} catch (e) {
console.error(e)
}
}
}
}