X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fworker%2Ftask-functions.ts;h=2fd951fb2ac03d71b820a1673561630f0c9d7736;hb=refs%2Fheads%2Fmaster;hp=b912f05c2f5c5d6f1032a4db3e4d353998acaca5;hpb=4ef0b45781a9a2a1416c4bb62d700a0c70e71145;p=poolifier.git diff --git a/src/worker/task-functions.ts b/src/worker/task-functions.ts index b912f05c..2fd951fb 100644 --- a/src/worker/task-functions.ts +++ b/src/worker/task-functions.ts @@ -1,8 +1,9 @@ +import type { WorkerChoiceStrategy } from '../pools/selection-strategies/selection-strategies-types.js' + /** * Task synchronous function that can be executed. - * * @param data - Data sent to the worker. - * + * @returns Execution response. * @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. */ @@ -13,9 +14,8 @@ export type TaskSyncFunction = ( /** * Task asynchronous function that can be executed. * This function must return a promise. - * * @param data - Data sent to the worker. - * + * @returns Execution response promise. * @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. */ @@ -26,7 +26,6 @@ export type TaskAsyncFunction = ( /** * Task function that can be executed. * This function can be synchronous or asynchronous. - * * @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. */ @@ -34,18 +33,36 @@ 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 + string, + TaskFunction | TaskFunctionObject > /**