| 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 | * Message object that is passed between worker and main worker. |
| 12 | */ |
| 13 | export interface MessageValue< |
| 14 | Data = unknown, |
| 15 | MainWorker extends Worker | MessagePort | unknown = unknown |
| 16 | > { |
| 17 | /** |
| 18 | * Input data that will be passed to the worker. |
| 19 | */ |
| 20 | readonly data?: Data |
| 21 | /** |
| 22 | * ID of the message. |
| 23 | */ |
| 24 | readonly id?: number |
| 25 | /** |
| 26 | * Kill code. |
| 27 | */ |
| 28 | readonly kill?: KillBehavior | 1 |
| 29 | /** |
| 30 | * Error. |
| 31 | */ |
| 32 | readonly error?: string |
| 33 | /** |
| 34 | * Reference to main worker. |
| 35 | * |
| 36 | * _Only for internal use_ |
| 37 | */ |
| 38 | readonly parent?: MainWorker |
| 39 | } |