From a038b5175071af7c51dae9e25c7423c7572f3949 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Thu, 20 Jul 2023 00:21:32 +0200 Subject: [PATCH] refactor: cleanup worker id handling code MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- src/pools/cluster/fixed.ts | 2 +- src/pools/thread/fixed.ts | 2 +- src/worker/abstract-worker.ts | 14 +++++++------- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/pools/cluster/fixed.ts b/src/pools/cluster/fixed.ts index d7e3cc4b..dbf1d470 100644 --- a/src/pools/cluster/fixed.ts +++ b/src/pools/cluster/fixed.ts @@ -77,7 +77,7 @@ export class FixedClusterPool< protected sendStartupMessageToWorker (worker: Worker): void { this.sendToWorker(worker, { ready: false, - workerId: this.getWorkerInfoByWorker(worker).id as number + workerId: worker.id }) } diff --git a/src/pools/thread/fixed.ts b/src/pools/thread/fixed.ts index 52868fd7..e3a94b32 100644 --- a/src/pools/thread/fixed.ts +++ b/src/pools/thread/fixed.ts @@ -79,7 +79,7 @@ export class FixedThreadPool< worker.postMessage( { ready: false, - workerId: this.getWorkerInfoByWorker(worker).id as number, + workerId: worker.threadId, port: port2 }, [port2] diff --git a/src/worker/abstract-worker.ts b/src/worker/abstract-worker.ts index 36b7d03e..67b4b5ff 100644 --- a/src/worker/abstract-worker.ts +++ b/src/worker/abstract-worker.ts @@ -284,6 +284,13 @@ export abstract class AbstractWorker< } } + /** + * Handles the ready message sent by the main worker. + * + * @param message - The ready message. + */ + protected abstract handleReadyMessage (message: MessageValue): void + /** * Worker message listener. * @@ -310,13 +317,6 @@ export abstract class AbstractWorker< } } - /** - * Handles the ready message sent by the main worker. - * - * @param message - The ready message. - */ - protected abstract handleReadyMessage (message: MessageValue): void - /** * Starts the worker check active interval. */ -- 2.34.1