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