From: Jérôme Benoit Date: Wed, 19 Jul 2023 22:03:59 +0000 (+0200) Subject: refactor: cleanup ready message conditions check in worker code X-Git-Tag: v2.6.19~9 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=6c0c538c652e072ffa0516bb2826c39b58b9592f;p=poolifier.git refactor: cleanup ready message conditions check in worker code Signed-off-by: Jérôme Benoit --- diff --git a/src/worker/abstract-worker.ts b/src/worker/abstract-worker.ts index 77d2e007..36b7d03e 100644 --- a/src/worker/abstract-worker.ts +++ b/src/worker/abstract-worker.ts @@ -73,7 +73,7 @@ export abstract class AbstractWorker< public constructor ( type: string, protected readonly isMain: boolean, - protected readonly mainWorker: MainWorker, + private readonly mainWorker: MainWorker, taskFunctions: | WorkerFunction | TaskFunctions, diff --git a/src/worker/cluster-worker.ts b/src/worker/cluster-worker.ts index c820641d..0e3bccd3 100644 --- a/src/worker/cluster-worker.ts +++ b/src/worker/cluster-worker.ts @@ -48,8 +48,8 @@ export class ClusterWorker< /** @inheritDoc */ protected handleReadyMessage (message: MessageValue): void { - if (message.workerId === this.id && message.ready != null) { - !this.isMain && this.sendToMainWorker({ ready: true, workerId: this.id }) + if (!this.isMain && message.workerId === this.id && message.ready != null) { + this.sendToMainWorker({ ready: true, workerId: this.id }) } } diff --git a/src/worker/thread-worker.ts b/src/worker/thread-worker.ts index a8658f03..98d58b5d 100644 --- a/src/worker/thread-worker.ts +++ b/src/worker/thread-worker.ts @@ -55,15 +55,14 @@ export class ThreadWorker< /** @inheritDoc */ protected handleReadyMessage (message: MessageValue): void { if ( + !this.isMain && message.workerId === this.id && message.ready != null && message.port != null ) { - if (!this.isMain) { - this.port = message.port - this.port.on('message', this.messageListener.bind(this)) - this.sendToMainWorker({ ready: true, workerId: this.id }) - } + this.port = message.port + this.port.on('message', this.messageListener.bind(this)) + this.sendToMainWorker({ ready: true, workerId: this.id }) } }