From d2dd5ef5081b45eea77be11cb857d3677889e165 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Tue, 19 Sep 2023 21:57:27 +0200 Subject: [PATCH] refactor: improve task function operation handling on the worker side MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- src/worker/abstract-worker.ts | 33 ++++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/src/worker/abstract-worker.ts b/src/worker/abstract-worker.ts index dc1f6adc..fde55a58 100644 --- a/src/worker/abstract-worker.ts +++ b/src/worker/abstract-worker.ts @@ -379,19 +379,26 @@ export abstract class AbstractWorker< ): void { const { taskFunctionOperation, taskFunctionName, taskFunction } = message let response!: TaskFunctionOperationResult - if (taskFunctionOperation === 'add') { - response = this.addTaskFunction( - taskFunctionName as string, - // eslint-disable-next-line @typescript-eslint/no-implied-eval, no-new-func - new Function(`return ${taskFunction as string}`)() as TaskFunction< - Data, - Response - > - ) - } else if (taskFunctionOperation === 'remove') { - response = this.removeTaskFunction(taskFunctionName as string) - } else if (taskFunctionOperation === 'default') { - response = this.setDefaultTaskFunction(taskFunctionName as string) + switch (taskFunctionOperation) { + case 'add': + response = this.addTaskFunction( + taskFunctionName as string, + // eslint-disable-next-line @typescript-eslint/no-implied-eval, no-new-func + new Function(`return ${taskFunction as string}`)() as TaskFunction< + Data, + Response + > + ) + break + case 'remove': + response = this.removeTaskFunction(taskFunctionName as string) + break + case 'default': + response = this.setDefaultTaskFunction(taskFunctionName as string) + break + default: + response = { status: false, error: new Error('Unknown task operation') } + break } this.sendToMainWorker({ taskFunctionOperation, -- 2.34.1