X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fpools%2Fpool.ts;h=212253ffbc5be7faff8760dc3847f9cdc486bb89;hb=16248b233364112df0972c0e9154941f561f09cc;hp=711a71bedb25205bef8b1fdbdaf4528866e92879;hpb=41e3e08eb7fbcde0a69cea17e697aacb222990a6;p=poolifier.git diff --git a/src/pools/pool.ts b/src/pools/pool.ts index 711a71be..212253ff 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, @@ -260,12 +261,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. *