From 7e627c2a5c5ffa392ad9bfd3750ed63d017a1782 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Thu, 20 Jul 2023 18:14:09 +0200 Subject: [PATCH] fix: register worker message handler only once the worker is ready MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- src/worker/cluster-worker.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/worker/cluster-worker.ts b/src/worker/cluster-worker.ts index 0e3bccd3..4c1e1187 100644 --- a/src/worker/cluster-worker.ts +++ b/src/worker/cluster-worker.ts @@ -41,14 +41,12 @@ export class ClusterWorker< taskFunctions, opts ) - if (!this.isMain) { - this.getMainWorker()?.on('message', this.messageListener.bind(this)) - } } /** @inheritDoc */ protected handleReadyMessage (message: MessageValue): void { if (!this.isMain && message.workerId === this.id && message.ready != null) { + this.getMainWorker()?.on('message', this.messageListener.bind(this)) this.sendToMainWorker({ ready: true, workerId: this.id }) } } -- 2.34.1