nanolith
nanolith copied to clipboard
Catching exceptions from `__initializeService`
Currently, the following code is in the runner for services:
// ! temp - enable catching errors in the __initializeService
// ! hook. This is only temporary because the "terminate()" function
// ! doesn't actually do anything. Eventually, closing a service should
// ! be done with message passing for more flexibility.
const initErrHandler = async (body: WorkerBaseMessageBody) => {
if (body.type !== WorkerMessageType.WorkerException) return;
await exceptionHandler?.({
error: (body as WorkerExceptionMessageBody).data,
terminate: () => {
//
},
});
};
The terminate()
functionality is completely empty, but when this function is called, the worker should be terminated. The Service
instance isn't created yet though, so service.close()
cannot be called (Service
is only initialized one the worker has notified that it is ready). The solution is to use message-passing in order to command the worker at a lower level (lower than Service
level).