docs: refine benchmarks README
[poolifier.git] / src / utility-types.ts
index 9cdf6b0a7e82f9d1e3da5fb434537ca8e2d943f9..bfbc2a84e376ac1db341614f6427943d5405285f 100644 (file)
@@ -11,26 +11,61 @@ import type { IWorker, Task } from './pools/worker'
  */
 export type Draft<T> = { -readonly [P in keyof T]?: T[P] }
 
+/**
+ * Task error.
+ *
+ * @typeParam Data - Type of data sent to the worker. This can only be serializable data.
+ */
+export interface TaskError<Data = unknown> {
+  /**
+   * Error message.
+   */
+  message: string
+  /**
+   * Data passed to the worker triggering the error.
+   */
+  data?: Data
+}
+
+/**
+ * Task performance.
+ */
+export interface TaskPerformance {
+  /**
+   * Task performance timestamp.
+   */
+  timestamp: number
+  /**
+   * Task runtime.
+   */
+  runTime?: number
+  /**
+   * Task event loop utilization.
+   */
+  elu?: EventLoopUtilization
+}
+
 /**
  * Performance statistics computation.
  */
 export interface WorkerStatistics {
   runTime: boolean
-  waitTime: boolean
   elu: boolean
 }
 
 /**
  * Message object that is passed between main worker and worker.
  *
+ * @typeParam MessageData - Type of data sent to and/or from the worker. This can only be serializable data.
  * @typeParam Data - Type of data sent to the worker. This can only be serializable data.
  * @typeParam MainWorker - Type of main worker.
  * @internal
  */
 export interface MessageValue<
+  MessageData = unknown,
   Data = unknown,
   MainWorker extends ClusterWorker | MessagePort = ClusterWorker | MessagePort
-> extends Task<Data> {
+> extends Task<MessageData> {
   /**
    * Kill code.
    */
@@ -38,23 +73,11 @@ export interface MessageValue<
   /**
    * Task error.
    */
-  readonly error?: string
-  /**
-   * Task data triggering task error.
-   */
-  readonly errorData?: unknown
-  /**
-   * Runtime.
-   */
-  readonly runTime?: number
-  /**
-   * Wait time.
-   */
-  readonly waitTime?: number
+  readonly taskError?: TaskError<Data>
   /**
-   * Event loop utilization.
+   * Task performance.
    */
-  readonly elu?: EventLoopUtilization
+  readonly taskPerformance?: TaskPerformance
   /**
    * Reference to main worker.
    */