From: Jérôme Benoit Date: Tue, 19 Sep 2023 19:57:27 +0000 (+0200) Subject: refactor: improve task function operation handling on the worker side X-Git-Tag: v2.7.1~17 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;ds=sidebyside;h=d2dd5ef5081b45eea77be11cb857d3677889e165;p=poolifier.git refactor: improve task function operation handling on the worker side Signed-off-by: Jérôme Benoit --- 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,