Commit | Line | Data |
---|---|---|
b6b32453 JB |
1 | /** |
2 | * Worker synchronous function that can be executed. | |
3 | * | |
e102732c JB |
4 | * @typeParam Data - Type of data sent to the worker. This can only be structured-cloneable data. |
5 | * @typeParam Response - Type of execution response. This can only be structured-cloneable data. | |
b6b32453 JB |
6 | */ |
7 | export type WorkerSyncFunction<Data = unknown, Response = unknown> = ( | |
8 | data?: Data | |
9 | ) => Response | |
10 | ||
11 | /** | |
12 | * Worker asynchronous function that can be executed. | |
13 | * This function must return a promise. | |
14 | * | |
e102732c JB |
15 | * @typeParam Data - Type of data sent to the worker. This can only be structured-cloneable data. |
16 | * @typeParam Response - Type of execution response. This can only be structured-cloneable data. | |
b6b32453 JB |
17 | */ |
18 | export type WorkerAsyncFunction<Data = unknown, Response = unknown> = ( | |
19 | data?: Data | |
20 | ) => Promise<Response> | |
21 | ||
22 | /** | |
23 | * Worker function that can be executed. | |
24 | * This function can be synchronous or asynchronous. | |
25 | * | |
e102732c JB |
26 | * @typeParam Data - Type of data sent to the worker. This can only be structured-cloneable data. |
27 | * @typeParam Response - Type of execution response. This can only be structured-cloneable data. | |
b6b32453 JB |
28 | */ |
29 | export type WorkerFunction<Data = unknown, Response = unknown> = | |
30 | | WorkerSyncFunction<Data, Response> | |
31 | | WorkerAsyncFunction<Data, Response> | |
32 | ||
33 | /** | |
34 | * Worker functions that can be executed. | |
35 | * This object can contain synchronous or asynchronous functions. | |
36 | * The key is the name of the function. | |
37 | * The value is the function itself. | |
38 | * | |
e102732c JB |
39 | * @typeParam Data - Type of data sent to the worker. This can only be structured-cloneable data. |
40 | * @typeParam Response - Type of execution response. This can only be structured-cloneable data. | |
b6b32453 JB |
41 | */ |
42 | export type TaskFunctions<Data = unknown, Response = unknown> = Record< | |
43 | string, | |
44 | WorkerFunction<Data, Response> | |
45 | > |