Install onerror and onmessageerror handlers on a freshly-created
worker so a crash inside the worker (uncaught throw, OOM during WASM
init, unserializable Comlink message) surfaces as a logged failure
and is removed from the active pool, rather than escaping to the
browser's window.onerror and freezing requests that are awaiting
Comlink replies from this worker.
Note: this is a best-effort safety net. Comlink-wrapped calls that
are mid-flight when the worker dies will still hang their callers —
route hot paths through runWithTimeout for the per-call timeout
that complements this handler.
Parameters
worker: Worker
workerNumber: number
onFailure: (worker:Worker,reason:string)=>void
Called with (worker, reason) so the pool can run
its eviction + post-eviction state mutation.
Install
onerrorandonmessageerrorhandlers on a freshly-created worker so a crash inside the worker (uncaught throw, OOM during WASM init, unserializable Comlink message) surfaces as a logged failure and is removed from the active pool, rather than escaping to the browser'swindow.onerrorand freezing requests that are awaiting Comlink replies from this worker.Note: this is a best-effort safety net. Comlink-wrapped calls that are mid-flight when the worker dies will still hang their callers — route hot paths through
runWithTimeoutfor the per-call timeout that complements this handler.