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. The pool's onFailure also rejects the
calls still awaiting a Comlink reply from this worker, which a
terminated worker never sends.
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.onerror. The pool'sonFailurealso rejects the calls still awaiting a Comlink reply from this worker, which a terminated worker never sends.