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