-
-
Notifications
You must be signed in to change notification settings - Fork 13
/
task-functions.ts
45 lines (42 loc) · 1.66 KB
/
task-functions.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
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 = unknown, Response = unknown> = (
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 = unknown, Response = unknown> = (
data?: Data
) => Promise<Response>
/**
* 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<Data = unknown, Response = unknown> =
| TaskSyncFunction<Data, Response>
| TaskAsyncFunction<Data, Response>
/**
* 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<Data = unknown, Response = unknown> = Record<
string,
TaskFunction<Data, Response>
>