nanolith icon indicating copy to clipboard operation
nanolith copied to clipboard

Catching exceptions from `__initializeService`

Open mstephen19 opened this issue 1 year ago • 0 comments

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).

mstephen19 avatar May 19 '23 02:05 mstephen19