X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fworker%2Ftask-functions.ts;fp=src%2Fworker%2Ftask-functions.ts;h=a61d69627ce6eeebd36e462f5801c36e94cc8e06;hb=82ea6492d3318a170559bb57501dc16023bb18d8;hp=0000000000000000000000000000000000000000;hpb=cb954063cd825d46276030815257fa686d08baa3;p=poolifier.git diff --git a/src/worker/task-functions.ts b/src/worker/task-functions.ts new file mode 100644 index 00000000..a61d6962 --- /dev/null +++ b/src/worker/task-functions.ts @@ -0,0 +1,45 @@ +/** + * Task synchronous function that can be executed. + * + * @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 TaskSyncFunction = ( + data?: Data +) => Response + +/** + * Task asynchronous function that can be executed. + * This function must return a 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. + */ +export type TaskAsyncFunction = ( + data?: Data +) => Promise + +/** + * 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. + */ +export type TaskFunction = + | TaskSyncFunction + | TaskAsyncFunction + +/** + * 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. + * + * @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 +>