| 1 | import type { WorkerChoiceStrategy } from './selection-strategies' |
| 2 | |
| 3 | /** |
| 4 | * Contract definition for a poolifier pool. |
| 5 | * |
| 6 | * @template Data Type of data sent to the worker. This can only be serializable data. |
| 7 | * @template Response Type of response of execution. This can only be serializable data. |
| 8 | */ |
| 9 | export interface IPool<Data = unknown, Response = unknown> { |
| 10 | /** |
| 11 | * Perform the task specified in the constructor with the data parameter. |
| 12 | * |
| 13 | * @param data The input for the specified task. This can only be serializable data. |
| 14 | * @returns Promise that will be resolved when the task is successfully completed. |
| 15 | */ |
| 16 | execute(data: Data): Promise<Response> |
| 17 | /** |
| 18 | * Shut down every current worker in this pool. |
| 19 | */ |
| 20 | destroy(): Promise<void> |
| 21 | /** |
| 22 | * Set the worker choice strategy in this pool. |
| 23 | * |
| 24 | * @param workerChoiceStrategy The worker choice strategy. |
| 25 | */ |
| 26 | setWorkerChoiceStrategy(workerChoiceStrategy: WorkerChoiceStrategy): void |
| 27 | } |