X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fpools%2Fpool.ts;h=c6fbce43aba1d6a31d825a1eff80db8aae49ee12;hb=2f8c5b5c1182f698efe07d327359bef934af3a29;hp=f48d8843d9596f914f60ae1349ff258af7df4518;hpb=deb85c12b77faf6974551cefcd9676e62a392086;p=poolifier.git diff --git a/src/pools/pool.ts b/src/pools/pool.ts index f48d8843..c6fbce43 100644 --- a/src/pools/pool.ts +++ b/src/pools/pool.ts @@ -1,3 +1,43 @@ +import type { + ErrorHandler, + ExitHandler, + MessageHandler, + OnlineHandler +} from './pool-worker' +import type { WorkerChoiceStrategy } from './selection-strategies/selection-strategies-types' + +/** + * Options for a poolifier pool. + */ +export interface PoolOptions { + /** + * A function that will listen for message event on each worker. + */ + messageHandler?: MessageHandler + /** + * A function that will listen for error event on each worker. + */ + errorHandler?: ErrorHandler + /** + * A function that will listen for online event on each worker. + */ + onlineHandler?: OnlineHandler + /** + * A function that will listen for exit event on each worker. + */ + exitHandler?: ExitHandler + /** + * The worker choice strategy to use in this pool. + */ + workerChoiceStrategy?: WorkerChoiceStrategy + /** + * Pool events emission. + * + * @default true + */ + enableEvents?: boolean +} + /** * Contract definition for a poolifier pool. * @@ -6,14 +46,20 @@ */ export interface IPool { /** - * Perform the task specified in the constructor with the data parameter. + * Performs the task specified in the constructor with the data parameter. * * @param data The input for the specified task. This can only be serializable data. * @returns Promise that will be resolved when the task is successfully completed. */ execute(data: Data): Promise /** - * Shut down every current worker in this pool. + * Shutdowns every current worker in this pool. */ destroy(): Promise + /** + * Sets the worker choice strategy in this pool. + * + * @param workerChoiceStrategy The worker choice strategy. + */ + setWorkerChoiceStrategy(workerChoiceStrategy: WorkerChoiceStrategy): void }