2 * Callback invoked if the worker has received a message.
4 export type MessageHandler
<Worker
> = (this: Worker
, m
: unknown
) => void
7 * Callback invoked if the worker raised an error.
9 export type ErrorHandler
<Worker
> = (this: Worker
, e
: Error) => void
12 * Callback invoked when the worker has started successfully.
14 export type OnlineHandler
<Worker
> = (this: Worker
) => void
17 * Callback invoked when the worker exits successfully.
19 export type ExitHandler
<Worker
> = (this: Worker
, code
: number) => void
22 * Interface that describes the minimum required implementation of listener events for a pool worker.
24 export interface IPoolWorker
{
26 * Register an event listener.
28 * @param event - The event.
29 * @param handler - The event listener.
31 on
: ((event
: 'message', handler
: MessageHandler
<this>) => void) &
32 ((event
: 'error', handler
: ErrorHandler
<this>) => void) &
33 ((event
: 'online', handler
: OnlineHandler
<this>) => void) &
34 ((event
: 'exit', handler
: ExitHandler
<this>) => void)
36 * Register a listener to the exit event that will only performed once.
38 * @param event - `'exit'`.
39 * @param handler - The exit handler.
41 once
: (event
: 'exit', handler
: ExitHandler
<this>) => void