X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fpools%2Fworker.ts;h=2da91457aed58994f01714a162adffba69ab61fe;hb=5af9e4679f4c53948b332cc775564e5a464ed822;hp=055a326ad6448add8c87d9a0bdfed8b325066770;hpb=ccd73e075194fac1cf6e1b736f1556b199c95bc5;p=poolifier.git diff --git a/src/pools/worker.ts b/src/pools/worker.ts index 055a326a..2da91457 100644 --- a/src/pools/worker.ts +++ b/src/pools/worker.ts @@ -1,4 +1,6 @@ +import type { MessageChannel } from 'node:worker_threads' import type { CircularArray } from '../circular-array' +import type { Task } from '../utility-types' /** * Callback invoked if the worker has received a message. @@ -29,35 +31,6 @@ export type ExitHandler = ( exitCode: number ) => void -/** - * 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 { - /** - * 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 -} - /** * Measurement statistics. * @@ -133,8 +106,8 @@ export interface TaskStatistics { * Enumeration of worker types. */ export const WorkerTypes = Object.freeze({ - cluster: 'cluster', - thread: 'thread' + thread: 'thread', + cluster: 'cluster' } as const) /** @@ -164,6 +137,10 @@ export interface WorkerInfo { * Ready flag. */ ready: boolean + /** + * Message channel. + */ + messageChannel?: MessageChannel } /** @@ -266,7 +243,11 @@ export interface IWorkerNode { */ readonly resetUsage: () => void /** - * Gets task usage statistics. + * Close communication channel. + */ + readonly closeChannel: () => void + /** + * Gets task worker usage statistics. */ readonly getTaskWorkerUsage: (name: string) => WorkerUsage | undefined }