Commit | Line | Data |
---|---|---|
b6b32453 | 1 | /** |
82ea6492 | 2 | * Task synchronous function that can be executed. |
b6b32453 | 3 | * |
09b75fef JB |
4 | * @param data - Data sent to the worker. |
5 | * | |
e102732c JB |
6 | * @typeParam Data - Type of data sent to the worker. This can only be structured-cloneable data. |
7 | * @typeParam Response - Type of execution response. This can only be structured-cloneable data. | |
b6b32453 | 8 | */ |
82ea6492 | 9 | export type TaskSyncFunction<Data = unknown, Response = unknown> = ( |
b6b32453 JB |
10 | data?: Data |
11 | ) => Response | |
12 | ||
13 | /** | |
82ea6492 | 14 | * Task asynchronous function that can be executed. |
b6b32453 JB |
15 | * This function must return a promise. |
16 | * | |
09b75fef JB |
17 | * @param data - Data sent to the worker. |
18 | * | |
e102732c JB |
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. | |
b6b32453 | 21 | */ |
82ea6492 | 22 | export type TaskAsyncFunction<Data = unknown, Response = unknown> = ( |
b6b32453 JB |
23 | data?: Data |
24 | ) => Promise<Response> | |
25 | ||
26 | /** | |
82ea6492 | 27 | * Task function that can be executed. |
b6b32453 JB |
28 | * This function can be synchronous or asynchronous. |
29 | * | |
e102732c JB |
30 | * @typeParam Data - Type of data sent to the worker. This can only be structured-cloneable data. |
31 | * @typeParam Response - Type of execution response. This can only be structured-cloneable data. | |
b6b32453 | 32 | */ |
82ea6492 JB |
33 | export type TaskFunction<Data = unknown, Response = unknown> = |
34 | | TaskSyncFunction<Data, Response> | |
35 | | TaskAsyncFunction<Data, Response> | |
b6b32453 JB |
36 | |
37 | /** | |
82ea6492 | 38 | * Tasks functions that can be executed. |
b6b32453 JB |
39 | * This object can contain synchronous or asynchronous functions. |
40 | * The key is the name of the function. | |
41 | * The value is the function itself. | |
42 | * | |
e102732c JB |
43 | * @typeParam Data - Type of data sent to the worker. This can only be structured-cloneable data. |
44 | * @typeParam Response - Type of execution response. This can only be structured-cloneable data. | |
b6b32453 JB |
45 | */ |
46 | export type TaskFunctions<Data = unknown, Response = unknown> = Record< | |
47 | string, | |
82ea6492 | 48 | TaskFunction<Data, Response> |
b6b32453 | 49 | > |
e81c38f2 JB |
50 | |
51 | /** | |
4e38fd21 | 52 | * Task function operation result. |
e81c38f2 | 53 | */ |
4e38fd21 | 54 | export interface TaskFunctionOperationResult { |
e81c38f2 JB |
55 | status: boolean |
56 | error?: Error | |
57 | } |