X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fworker%2Ftask-functions.ts;h=0b3083c3aed6ca892af39070734c1562648f69af;hb=910416386b4f7d0da4e6f0d8551cefa2539c5ced;hp=5518043eb022857209401a32ecd0a0a9d18bcf30;hpb=77e8da5a0633e5a282ddc82f52b354101d112f0f;p=poolifier.git diff --git a/src/worker/task-functions.ts b/src/worker/task-functions.ts index 5518043e..0b3083c3 100644 --- a/src/worker/task-functions.ts +++ b/src/worker/task-functions.ts @@ -1,3 +1,5 @@ +import type { WorkerChoiceStrategy } from '../pools/selection-strategies/selection-strategies-types.js' + /** * Task synchronous function that can be executed. * @@ -36,18 +38,38 @@ export type TaskFunction = | TaskSyncFunction | TaskAsyncFunction +/** + * Task function object. + * + * @typeParam Data - Type of data sent to the worker. This can only be structured-cloneable data. + * @typeParam Response - Type of execution response. This can only be structured-cloneable data. + */ +export interface TaskFunctionObject { + /** + * Task function. + */ + taskFunction: TaskFunction + /** + * Task function priority. Lower values have higher priority. + */ + priority?: number + /** + * Task function worker choice strategy. + */ + strategy?: WorkerChoiceStrategy +} + /** * Tasks functions that can be executed. - * This object can contain synchronous or asynchronous functions. - * The key is the name of the function. - * The value is the function itself. + * The key is the name of the task function or task function object. + * The value is the task function or task function object. * * @typeParam Data - Type of data sent to the worker. This can only be structured-cloneable data. * @typeParam Response - Type of execution response. This can only be structured-cloneable data. */ export type TaskFunctions = Record< string, -TaskFunction +TaskFunction | TaskFunctionObject > /**