) => void
/**
- * Worker task interface.
+ * Message object that is passed as a task between main worker and worker.
+ *
+ * @typeParam Data - Type of data sent to the worker. This can only be serializable data.
+ * @internal
*/
export interface Task<Data = unknown> {
- data: Data
- id: string
+ /**
+ * Task input data that will be passed to the worker.
+ */
+ readonly data?: Data
+ /**
+ * UUID of the message.
+ */
+ readonly id?: string
}
/**
* Worker tasks usage statistics.
+ *
+ * @internal
*/
export interface TasksUsage {
+ /**
+ * Number of tasks executed.
+ */
run: number
+ /**
+ * Number of tasks running.
+ */
running: number
+ /**
+ * Tasks runtime.
+ */
runTime: number
+ /**
+ * Tasks runtime history.
+ */
runTimeHistory: CircularArray<number>
+ /**
+ * Average tasks runtime.
+ */
avgRunTime: number
+ /**
+ * Median tasks runtime.
+ */
medRunTime: number
+ /**
+ * Number of tasks errored.
+ */
error: number
}
/**
* Worker node interface.
+ *
+ * @typeParam Worker - Type of worker.
+ * @typeParam Data - Type of data sent to the worker. This can only be serializable data.
+ * @internal
*/
export interface WorkerNode<Worker extends IWorker, Data = unknown> {
- worker: Worker
+ /**
+ * Worker node worker.
+ */
+ readonly worker: Worker
+ /**
+ * Worker node tasks usage statistics.
+ */
tasksUsage: TasksUsage
- tasksQueue: Array<Task<Data>>
+ /**
+ * Worker node tasks queue.
+ */
+ readonly tasksQueue: Array<Task<Data>>
}