From c26984f2a8831eeb78ce791837f0032fd4bc8824 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Thu, 20 Jul 2023 21:48:08 +0200 Subject: [PATCH] feat: add worker set events MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- src/worker/WorkerSet.ts | 8 ++++++++ src/worker/WorkerTypes.ts | 2 ++ 2 files changed, 10 insertions(+) diff --git a/src/worker/WorkerSet.ts b/src/worker/WorkerSet.ts index 19ed8393..bc1a4c08 100644 --- a/src/worker/WorkerSet.ts +++ b/src/worker/WorkerSet.ts @@ -10,6 +10,7 @@ import { WorkerConstants } from './WorkerConstants'; import { type SetInfo, type WorkerData, + type WorkerMessage, WorkerMessageEvents, type WorkerOptions, type WorkerSetElement, @@ -116,6 +117,13 @@ export class WorkerSet extends WorkerAbstract { 'message', this.workerOptions.poolOptions?.messageHandler ?? WorkerConstants.EMPTY_FUNCTION, ); + worker.on('message', (message: WorkerMessage) => { + if (message.event === WorkerMessageEvents.startedWorkerElement) { + this.emitter?.emit(WorkerSetEvents.elementStarted, message.data); + } else if (message.event === WorkerMessageEvents.startWorkerElementError) { + this.emitter?.emit(WorkerSetEvents.elementError, message.data); + } + }); worker.on( 'error', this.workerOptions.poolOptions?.errorHandler ?? WorkerConstants.EMPTY_FUNCTION, diff --git a/src/worker/WorkerTypes.ts b/src/worker/WorkerTypes.ts index 653cfedf..12d5ab26 100644 --- a/src/worker/WorkerTypes.ts +++ b/src/worker/WorkerTypes.ts @@ -20,6 +20,8 @@ export interface SetInfo { export enum WorkerSetEvents { error = 'error', + elementStarted = 'elementStarted', + elementError = 'elementError', } export const WorkerEvents = { -- 2.34.1