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