1 import type { WorkerChoiceStrategy
} from
'../pools/selection-strategies/selection-strategies-types.js'
4 * Task synchronous function that can be executed.
6 * @param data - Data sent to the worker.
7 * @returns Execution response.
9 * @typeParam Data - Type of data sent to the worker. This can only be structured-cloneable data.
10 * @typeParam Response - Type of execution response. This can only be structured-cloneable data.
12 export type TaskSyncFunction
<Data
= unknown
, Response
= unknown
> = (
17 * Task asynchronous function that can be executed.
18 * This function must return a promise.
20 * @param data - Data sent to the worker.
21 * @returns Execution response promise.
23 * @typeParam Data - Type of data sent to the worker. This can only be structured-cloneable data.
24 * @typeParam Response - Type of execution response. This can only be structured-cloneable data.
26 export type TaskAsyncFunction
<Data
= unknown
, Response
= unknown
> = (
28 ) => Promise
<Response
>
31 * Task function that can be executed.
32 * This function can be synchronous or asynchronous.
34 * @typeParam Data - Type of data sent to the worker. This can only be structured-cloneable data.
35 * @typeParam Response - Type of execution response. This can only be structured-cloneable data.
37 export type TaskFunction
<Data
= unknown
, Response
= unknown
> =
38 | TaskSyncFunction
<Data
, Response
>
39 | TaskAsyncFunction
<Data
, Response
>
42 * Task function object.
44 * @typeParam Data - Type of data sent to the worker. This can only be structured-cloneable data.
45 * @typeParam Response - Type of execution response. This can only be structured-cloneable data.
47 export interface TaskFunctionObject
<Data
= unknown
, Response
= unknown
> {
51 taskFunction
: TaskFunction
<Data
, Response
>
53 * Task function priority. Lower values have higher priority.
57 * Task function worker choice strategy.
59 strategy
?: WorkerChoiceStrategy
63 * Tasks functions that can be executed.
64 * The key is the name of the task function or task function object.
65 * The value is the task function or task function object.
67 * @typeParam Data - Type of data sent to the worker. This can only be structured-cloneable data.
68 * @typeParam Response - Type of execution response. This can only be structured-cloneable data.
70 export type TaskFunctions
<Data
= unknown
, Response
= unknown
> = Record
<
72 TaskFunction
<Data
, Response
> | TaskFunctionObject
<Data
, Response
>
76 * Task function operation result.
78 export interface TaskFunctionOperationResult
{