X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fpools%2Fpool.ts;h=3b8234d99bdf23363f0ad0245b94bf43eec136d0;hb=297d705dc3cac3e998e4ce25f1e7ee76c3b94be6;hp=b5eec21c714798099076be2dab22f64aec4722ac;hpb=dbd73092cca6cabb2b41e18b944656fc43f8757b;p=poolifier.git diff --git a/src/pools/pool.ts b/src/pools/pool.ts index b5eec21c..3b8234d9 100644 --- a/src/pools/pool.ts +++ b/src/pools/pool.ts @@ -1,5 +1,6 @@ import { EventEmitter } from 'node:events' import { type TransferListItem } from 'node:worker_threads' +import type { TaskFunction } from '../worker/task-functions' import type { ErrorHandler, ExitHandler, @@ -152,7 +153,7 @@ export interface PoolOptions { /** * Whether to start the minimum number of workers at pool initialization. * - * @defaultValue false + * @defaultValue true */ startWorkers?: boolean /** @@ -252,12 +253,45 @@ export interface IPool< * Terminates all workers in this pool. */ readonly destroy: () => Promise + /** + * Whether the specified task function exists in this pool. + * + * @param name - The name of the task function. + * @returns `true` if the task function exists, `false` otherwise. + */ + readonly hasTaskFunction: (name: string) => boolean + /** + * Adds a task function to this pool. + * If a task function with the same name already exists, it will be overwritten. + * + * @param name - The name of the task function. + * @param taskFunction - The task function. + * @returns `true` if the task function was added, `false` otherwise. + */ + readonly addTaskFunction: ( + name: string, + taskFunction: TaskFunction + ) => Promise + /** + * Removes a task function from this pool. + * + * @param name - The name of the task function. + * @returns `true` if the task function was removed, `false` otherwise. + */ + readonly removeTaskFunction: (name: string) => Promise /** * Lists the names of task function available in this pool. * * @returns The names of task function available in this pool. */ - readonly listTaskFunctions: () => string[] + readonly listTaskFunctionNames: () => string[] + /** + * Sets the default task function in this pool. + * + * @param name - The name of the task function. + * @returns `true` if the default task function was set, `false` otherwise. + */ + readonly setDefaultTaskFunction: (name: string) => Promise /** * Sets the worker choice strategy in this pool. *