Improve jsdoc comments (#175)
[poolifier.git] / src / utility-types.ts
CommitLineData
838898f1
S
1import type { Worker } from 'cluster'
2import type { MessagePort } from 'worker_threads'
1a81f8af 3import type { KillBehavior } from './worker/worker-options'
838898f1 4
729c563d 5/**
3832ad95 6 * Make all properties in T non-readonly.
729c563d 7 */
325f50bc
S
8export type Draft<T> = { -readonly [P in keyof T]?: T[P] }
9
729c563d
S
10/**
11 * Serializable primitive JSON value.
12 */
d3c8a1a8 13export 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
18export type JSONValue = JSONPrimitive | JSONArray | JSONObject
729c563d
S
19/**
20 * Serializable JSON object.
21 */
d3c8a1a8 22export type JSONObject = { [k: string]: JSONValue }
729c563d
S
23/**
24 * Serializable JSON array.
25 */
d3c8a1a8
S
26export type JSONArray = Array<JSONValue>
27
729c563d
S
28/**
29 * Message object that is passed between worker and main worker.
30 */
838898f1
S
31export 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 */
1a81f8af 46 readonly kill?: KillBehavior | 1
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}