-
-
Notifications
You must be signed in to change notification settings - Fork 13
/
utility-types.ts
65 lines (62 loc) · 1.59 KB
/
utility-types.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import type { Worker as ClusterWorker } from 'node:cluster'
import type { MessagePort } from 'node:worker_threads'
import type { KillBehavior } from './worker/worker-options'
import type { IWorker, Task } from './pools/worker'
/**
* Make all properties in T non-readonly.
*
* @typeParam T - Type in which properties will be non-readonly.
*/
export type Draft<T> = { -readonly [P in keyof T]?: T[P] }
/**
* Message object that is passed between main worker and worker.
*
* @typeParam Data - Type of data sent to the worker. This can only be serializable data.
* @typeParam MainWorker - Type of main worker.
* @internal
*/
export interface MessageValue<
Data = unknown,
MainWorker extends ClusterWorker | MessagePort | unknown = unknown
> extends Task<Data> {
/**
* Kill code.
*/
readonly kill?: KillBehavior | 1
/**
* Error.
*/
readonly error?: string
/**
* Runtime.
*/
readonly runTime?: number
/**
* Reference to main worker.
*/
readonly parent?: MainWorker
}
/**
* An object holding the execution response promise resolve/reject callbacks.
*
* @typeParam Worker - Type of worker.
* @typeParam Response - Type of execution response. This can only be serializable data.
* @internal
*/
export interface PromiseResponseWrapper<
Worker extends IWorker,
Response = unknown
> {
/**
* Resolve callback to fulfill the promise.
*/
readonly resolve: (value: Response) => void
/**
* Reject callback to reject the promise.
*/
readonly reject: (reason?: string) => void
/**
* The worker handling the execution.
*/
readonly worker: Worker
}