7 import type { WorkerChoiceStrategy
} from
'./selection-strategies/selection-strategies-types'
10 * Options for a poolifier pool.
12 export interface PoolOptions
<Worker
> {
14 * A function that will listen for message event on each worker.
16 messageHandler
?: MessageHandler
<Worker
>
18 * A function that will listen for error event on each worker.
20 errorHandler
?: ErrorHandler
<Worker
>
22 * A function that will listen for online event on each worker.
24 onlineHandler
?: OnlineHandler
<Worker
>
26 * A function that will listen for exit event on each worker.
28 exitHandler
?: ExitHandler
<Worker
>
30 * The worker choice strategy to use in this pool.
32 workerChoiceStrategy
?: WorkerChoiceStrategy
34 * Pool events emission.
38 enableEvents
?: boolean
42 * Contract definition for a poolifier pool.
44 * @template Data Type of data sent to the worker. This can only be serializable data.
45 * @template Response Type of response of execution. This can only be serializable data.
47 export interface IPool
<Data
= unknown
, Response
= unknown
> {
49 * Performs the task specified in the constructor with the data parameter.
51 * @param data The input for the specified task. This can only be serializable data.
52 * @returns Promise that will be resolved when the task is successfully completed.
54 execute(data
: Data
): Promise
<Response
>
56 * Shutdowns every current worker in this pool.
58 destroy(): Promise
<void>
60 * Sets the worker choice strategy in this pool.
62 * @param workerChoiceStrategy The worker choice strategy.
64 setWorkerChoiceStrategy(workerChoiceStrategy
: WorkerChoiceStrategy
): void