From: Jérôme Benoit Date: Tue, 7 May 2024 21:48:34 +0000 (+0200) Subject: refactor: cleanup worker message channel handling X-Git-Tag: v4.0.3~4 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=43805f1db04b0d52ec9a43b569ce68b759f5fa53;p=poolifier.git refactor: cleanup worker message channel handling Signed-off-by: Jérôme Benoit --- diff --git a/src/worker/abstract-worker.ts b/src/worker/abstract-worker.ts index 2a5f1121..bb6ac566 100644 --- a/src/worker/abstract-worker.ts +++ b/src/worker/abstract-worker.ts @@ -324,19 +324,27 @@ export abstract class AbstractWorker< */ protected messageListener (message: MessageValue): void { this.checkMessageWorkerId(message) - if (message.statistics != null) { + const { + statistics, + checkActive, + taskFunctionOperation, + taskId, + data, + kill + } = message + if (statistics != null) { // Statistics message received - this.statistics = message.statistics - } else if (message.checkActive != null) { + this.statistics = statistics + } else if (checkActive != null) { // Check active message received - message.checkActive ? this.startCheckActive() : this.stopCheckActive() - } else if (message.taskFunctionOperation != null) { + checkActive ? this.startCheckActive() : this.stopCheckActive() + } else if (taskFunctionOperation != null) { // Task function operation message received this.handleTaskFunctionOperationMessage(message) - } else if (message.taskId != null && message.data != null) { + } else if (taskId != null && data != null) { // Task message received this.run(message) - } else if (message.kill === true) { + } else if (kill === true) { // Kill message received this.handleKillMessage(message) }