build(deps): bump poolifier
[poolifier.git] / src / worker / task-functions.ts
CommitLineData
b6b32453 1/**
82ea6492 2 * Task synchronous function that can be executed.
b6b32453 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 6 */
82ea6492 7export type TaskSyncFunction<Data = unknown, Response = unknown> = (
b6b32453
JB
8 data?: Data
9) => Response
10
11/**
82ea6492 12 * Task asynchronous function that can be executed.
b6b32453
JB
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 17 */
82ea6492 18export type TaskAsyncFunction<Data = unknown, Response = unknown> = (
b6b32453
JB
19 data?: Data
20) => Promise<Response>
21
22/**
82ea6492 23 * Task function that can be executed.
b6b32453
JB
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 28 */
82ea6492
JB
29export type TaskFunction<Data = unknown, Response = unknown> =
30 | TaskSyncFunction<Data, Response>
31 | TaskAsyncFunction<Data, Response>
b6b32453
JB
32
33/**
82ea6492 34 * Tasks functions that can be executed.
b6b32453
JB
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 */
42export type TaskFunctions<Data = unknown, Response = unknown> = Record<
43string,
82ea6492 44TaskFunction<Data, Response>
b6b32453 45>