From: Jérôme Benoit Date: Thu, 20 Jul 2023 16:14:09 +0000 (+0200) Subject: fix: register worker message handler only once the worker is ready X-Git-Tag: v2.6.19~2 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=7e627c2a5c5ffa392ad9bfd3750ed63d017a1782;p=poolifier.git fix: register worker message handler only once the worker is ready Signed-off-by: Jérôme Benoit --- 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 }) } }