Commit | Line | Data |
---|---|---|
838898f1 S |
1 | import type { Worker } from 'cluster' |
2 | import type { MessagePort } from 'worker_threads' | |
3 | ||
729c563d S |
4 | /** |
5 | * Make all properties in T non-readonly | |
6 | */ | |
325f50bc S |
7 | export type Draft<T> = { -readonly [P in keyof T]?: T[P] } |
8 | ||
729c563d S |
9 | /** |
10 | * Serializable primitive JSON value. | |
11 | */ | |
d3c8a1a8 | 12 | export type JSONPrimitive = number | boolean | string | null |
729c563d S |
13 | /** |
14 | * Serializable JSON value. | |
15 | */ | |
d3c8a1a8 S |
16 | // eslint-disable-next-line no-use-before-define |
17 | export type JSONValue = JSONPrimitive | JSONArray | JSONObject | |
729c563d S |
18 | /** |
19 | * Serializable JSON object. | |
20 | */ | |
d3c8a1a8 | 21 | export type JSONObject = { [k: string]: JSONValue } |
729c563d S |
22 | /** |
23 | * Serializable JSON array. | |
24 | */ | |
d3c8a1a8 S |
25 | export type JSONArray = Array<JSONValue> |
26 | ||
729c563d S |
27 | /** |
28 | * Message object that is passed between worker and main worker. | |
29 | */ | |
838898f1 S |
30 | export interface MessageValue< |
31 | Data = unknown, | |
32 | MainWorker extends Worker | MessagePort | unknown = unknown | |
33 | > { | |
729c563d S |
34 | /** |
35 | * Input data that will be passed to the worker. | |
36 | */ | |
325f50bc | 37 | readonly data?: Data |
729c563d S |
38 | /** |
39 | * ID of the message. | |
40 | */ | |
325f50bc | 41 | readonly id?: number |
729c563d S |
42 | /** |
43 | * Kill code. | |
44 | */ | |
325f50bc | 45 | readonly kill?: number |
729c563d S |
46 | /** |
47 | * Error. | |
48 | */ | |
325f50bc | 49 | readonly error?: string |
729c563d S |
50 | /** |
51 | * Reference to main worker. | |
52 | * | |
53 | * _Only for internal use_ | |
54 | */ | |
838898f1 | 55 | readonly parent?: MainWorker |
325f50bc | 56 | } |