Commit | Line | Data |
---|---|---|
bdaf31cd JB |
1 | /** |
2 | * Callback invoked if the worker has received a message. | |
3 | */ | |
4 | export type MessageHandler<Worker> = (this: Worker, m: unknown) => void | |
5 | ||
6 | /** | |
7 | * Callback invoked if the worker raised an error. | |
8 | */ | |
9 | export type ErrorHandler<Worker> = (this: Worker, e: Error) => void | |
10 | ||
11 | /** | |
12 | * Callback invoked when the worker has started successfully. | |
13 | */ | |
14 | export type OnlineHandler<Worker> = (this: Worker) => void | |
15 | ||
16 | /** | |
17 | * Callback invoked when the worker exits successfully. | |
18 | */ | |
19 | export type ExitHandler<Worker> = (this: Worker, code: number) => void | |
20 | ||
21 | /** | |
ea7a90d3 | 22 | * Interface that describes the minimum required implementation of listener events for a pool worker. |
bdaf31cd JB |
23 | */ |
24 | export interface IPoolWorker { | |
bdaf31cd | 25 | /** |
78cea37e | 26 | * Register an event listener. |
bdaf31cd | 27 | * |
38e795c1 JB |
28 | * @param event - The event. |
29 | * @param handler - The event listener. | |
bdaf31cd | 30 | */ |
78cea37e JB |
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) | |
bdaf31cd JB |
35 | /** |
36 | * Register a listener to the exit event that will only performed once. | |
37 | * | |
38e795c1 JB |
38 | * @param event - `'exit'`. |
39 | * @param handler - The exit handler. | |
bdaf31cd | 40 | */ |
78cea37e | 41 | once: (event: 'exit', handler: ExitHandler<this>) => void |
bdaf31cd | 42 | } |