1 import type { WorkerChoiceStrategy
} from
'../pools/selection-strategies/selection-strategies-types.js'
4 * Task synchronous function that can be executed.
5 * @param data - Data sent to the worker.
6 * @returns Execution response.
7 * @typeParam Data - Type of data sent to the worker. This can only be structured-cloneable data.
8 * @typeParam Response - Type of execution response. This can only be structured-cloneable data.
10 export type TaskSyncFunction
<Data
= unknown
, Response
= unknown
> = (
15 * Task asynchronous function that can be executed.
16 * This function must return a promise.
17 * @param data - Data sent to the worker.
18 * @returns Execution response promise.
19 * @typeParam Data - Type of data sent to the worker. This can only be structured-cloneable data.
20 * @typeParam Response - Type of execution response. This can only be structured-cloneable data.
22 export type TaskAsyncFunction
<Data
= unknown
, Response
= unknown
> = (
24 ) => Promise
<Response
>
27 * Task function that can be executed.
28 * This function can be synchronous or asynchronous.
29 * @typeParam Data - Type of data sent to the worker. This can only be structured-cloneable data.
30 * @typeParam Response - Type of execution response. This can only be structured-cloneable data.
32 export type TaskFunction
<Data
= unknown
, Response
= unknown
> =
33 | TaskSyncFunction
<Data
, Response
>
34 | TaskAsyncFunction
<Data
, Response
>
37 * Task function object.
38 * @typeParam Data - Type of data sent to the worker. This can only be structured-cloneable data.
39 * @typeParam Response - Type of execution response. This can only be structured-cloneable data.
41 export interface TaskFunctionObject
<Data
= unknown
, Response
= unknown
> {
45 taskFunction
: TaskFunction
<Data
, Response
>
47 * Task function priority. Lower values have higher priority.
51 * Task function worker choice strategy.
53 strategy
?: WorkerChoiceStrategy
57 * Tasks functions that can be executed.
58 * The key is the name of the task function or task function object.
59 * The value is the task function or task function object.
60 * @typeParam Data - Type of data sent to the worker. This can only be structured-cloneable data.
61 * @typeParam Response - Type of execution response. This can only be structured-cloneable data.
63 export type TaskFunctions
<Data
= unknown
, Response
= unknown
> = Record
<
65 TaskFunction
<Data
, Response
> | TaskFunctionObject
<Data
, Response
>
69 * Task function operation result.
71 export interface TaskFunctionOperationResult
{