refactor: incrementation consistency
[poolifier.git] / src / utility-types.ts
index a8da491e16fe62143d1d716672c4b4db44aa8e9f..28bf19e256abaef2f619051773ad55456643b842 100644 (file)
@@ -1,6 +1,6 @@
 import type { EventLoopUtilization } from 'node:perf_hooks'
 import type { KillBehavior } from './worker/worker-options'
-import type { IWorker, Task } from './pools/worker'
+import type { IWorker } from './pools/worker'
 
 /**
  * Task error.
@@ -8,12 +8,16 @@ import type { IWorker, Task } from './pools/worker'
  * @typeParam Data - Type of data sent to the worker triggering an error. This can only be structured-cloneable data.
  */
 export interface TaskError<Data = unknown> {
+  /**
+   * Task name triggering the error.
+   */
+  readonly name: string
   /**
    * Error message.
    */
   readonly message: string
   /**
-   * Data passed to the worker triggering the error.
+   * Data triggering the error.
    */
   readonly data?: Data
 }
@@ -24,6 +28,10 @@ export interface TaskError<Data = unknown> {
  * @internal
  */
 export interface TaskPerformance {
+  /**
+   * Task name.
+   */
+  readonly name: string
   /**
    * Task performance timestamp.
    */
@@ -48,6 +56,35 @@ export interface WorkerStatistics {
   elu: boolean
 }
 
+/**
+ * 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 structured-cloneable data.
+ * @internal
+ */
+export interface Task<Data = unknown> {
+  /**
+   * Worker id.
+   */
+  readonly workerId: number
+  /**
+   * Task name.
+   */
+  readonly name?: string
+  /**
+   * Task input data that will be passed to the worker.
+   */
+  readonly data?: Data
+  /**
+   * Timestamp.
+   */
+  readonly timestamp?: number
+  /**
+   * Message UUID.
+   */
+  readonly id?: string
+}
+
 /**
  * Message object that is passed between main worker and worker.
  *