X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Futility-types.ts;h=bfbc2a84e376ac1db341614f6427943d5405285f;hb=f1c0693012b2ec60fe1a0cbf457015b3f874e96f;hp=9cdf6b0a7e82f9d1e3da5fb434537ca8e2d943f9;hpb=b6b3245344bd453ea91fa3d74acd5145f70d84fd;p=poolifier.git diff --git a/src/utility-types.ts b/src/utility-types.ts index 9cdf6b0a..bfbc2a84 100644 --- a/src/utility-types.ts +++ b/src/utility-types.ts @@ -11,26 +11,61 @@ import type { IWorker, Task } from './pools/worker' */ export type Draft = { -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 { + /** + * 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 { +> extends Task { /** * 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 /** - * Event loop utilization. + * Task performance. */ - readonly elu?: EventLoopUtilization + readonly taskPerformance?: TaskPerformance /** * Reference to main worker. */