X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Futility-types.ts;h=fa1c0ffefdf27e6996789cc444f44d81de9076fc;hb=67e8ef11907ab8ae70740d7c9f4d5d225ed8d522;hp=9441fec4e420292905a23150d73580e73b3411cd;hpb=be0676b3936d75f22ce55b0f71a1fb03d008a01c;p=poolifier.git diff --git a/src/utility-types.ts b/src/utility-types.ts index 9441fec4..fa1c0ffe 100644 --- a/src/utility-types.ts +++ b/src/utility-types.ts @@ -1,51 +1,104 @@ -import type { Worker } from 'cluster' -import type { MessagePort } from 'worker_threads' -import type { IWorker } from './pools/abstract-pool' +import type { EventLoopUtilization } from 'node:perf_hooks' import type { KillBehavior } from './worker/worker-options' +import type { IWorker, Task } from './pools/worker' /** - * Make all properties in T non-readonly. + * Task error. + * + * @typeParam Data - Type of data sent to the worker triggering an error. This can only be structured-cloneable data. */ -export type Draft = { -readonly [P in keyof T]?: T[P] } +export interface TaskError { + /** + * Task name triggering the error. + */ + readonly name: string + /** + * Error message. + */ + readonly message: string + /** + * Data triggering the error. + */ + readonly data?: Data +} /** - * Message object that is passed between worker and main worker. + * Task performance. + * + * @internal */ -export interface MessageValue< - Data = unknown, - MainWorker extends Worker | MessagePort | unknown = unknown -> { +export interface TaskPerformance { /** - * Input data that will be passed to the worker. + * Task name. */ - readonly data?: Data + readonly name: string + /** + * Task performance timestamp. + */ + readonly timestamp: number + /** + * Task runtime. + */ + readonly runTime?: number /** - * ID of the message. + * Task event loop utilization. */ - readonly id?: number + readonly elu?: EventLoopUtilization +} + +/** + * Performance statistics computation. + * + * @internal + */ +export interface WorkerStatistics { + runTime: boolean + elu: boolean +} + +/** + * Message object that is passed between main worker and worker. + * + * @typeParam Data - Type of data sent to the worker or execution response. This can only be structured-cloneable data. + * @typeParam ErrorData - Type of data sent to the worker triggering an error. This can only be structured-cloneable data. + * @internal + */ +export interface MessageValue + extends Task { /** * Kill code. */ - readonly kill?: KillBehavior | 1 + readonly kill?: KillBehavior | true + /** + * Task error. + */ + readonly taskError?: TaskError + /** + * Task performance. + */ + readonly taskPerformance?: TaskPerformance + /** + * Whether the worker computes the given statistics or not. + */ + readonly statistics?: WorkerStatistics /** - * Error. + * Whether the worker is ready or not. */ - readonly error?: string + readonly ready?: boolean /** - * Reference to main worker. - * - * _Only for internal use_ + * Whether the worker starts or stops its aliveness check. */ - readonly parent?: MainWorker + readonly checkAlive?: boolean } /** - * An object holding the worker that will be used to resolve/rejects the promise later on. + * An object holding the execution response promise resolve/reject callbacks. * - * @template Worker Type of worker. - * @template Response Type of response of execution. This can only be serializable data. + * @typeParam Worker - Type of worker. + * @typeParam Response - Type of execution response. This can only be structured-cloneable data. + * @internal */ -export interface PromiseWorkerResponseWrapper< +export interface PromiseResponseWrapper< Worker extends IWorker, Response = unknown > { @@ -58,7 +111,7 @@ export interface PromiseWorkerResponseWrapper< */ readonly reject: (reason?: string) => void /** - * The worker that has the assigned task. + * The worker handling the execution. */ readonly worker: Worker }