From 0fd6ad4619f547ee56218f2ef45ea1a36c4b0dfe Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Tue, 24 Sep 2024 18:44:45 +0200 Subject: [PATCH] build(ci): silence linter error 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 | 36 ++++++++++++++++++++--------------- src/worker/cluster-worker.ts | 2 +- src/worker/thread-worker.ts | 2 +- 3 files changed, 23 insertions(+), 17 deletions(-) diff --git a/src/worker/abstract-worker.ts b/src/worker/abstract-worker.ts index 57f64171..53ec62f9 100644 --- a/src/worker/abstract-worker.ts +++ b/src/worker/abstract-worker.ts @@ -179,7 +179,7 @@ export abstract class AbstractWorker< protected statistics?: WorkerStatistics /** - * Task function object(s) processed by the worker when the pool's `execution` function is invoked. + * Task function object(s) processed by the worker when the pool's `execute` method is invoked. */ protected taskFunctions!: Map> @@ -187,7 +187,7 @@ export abstract class AbstractWorker< * Constructs a new poolifier worker. * @param isMain - Whether this is the main worker or not. * @param mainWorker - Reference to main worker. - * @param taskFunctions - Task function(s) processed by the worker when the pool's `execution` function is invoked. The first function is the default function. + * @param taskFunctions - Task function(s) processed by the worker when the pool's `execute` method is invoked. The first function is the default function. * @param opts - Options for the worker. */ public constructor ( @@ -272,19 +272,25 @@ export abstract class AbstractWorker< let response: TaskFunctionOperationResult switch (taskFunctionOperation) { case 'add': - response = this.addTaskFunction(taskFunctionProperties.name, { - // eslint-disable-next-line @typescript-eslint/no-implied-eval, no-new-func - taskFunction: new Function( - // eslint-disable-next-line @typescript-eslint/no-non-null-assertion - `return ${taskFunction!}` - )() as TaskFunction, - ...(taskFunctionProperties.priority != null && { - priority: taskFunctionProperties.priority, - }), - ...(taskFunctionProperties.strategy != null && { - strategy: taskFunctionProperties.strategy, - }), - }) + if (typeof taskFunction === 'string') { + response = this.addTaskFunction(taskFunctionProperties.name, { + // eslint-disable-next-line @typescript-eslint/no-implied-eval, no-new-func, @typescript-eslint/no-unsafe-call + taskFunction: new Function( + `return ${taskFunction}` + )() as TaskFunction, + ...(taskFunctionProperties.priority != null && { + priority: taskFunctionProperties.priority, + }), + ...(taskFunctionProperties.strategy != null && { + strategy: taskFunctionProperties.strategy, + }), + }) + } else { + response = { + error: new Error("'taskFunction' property is not a string"), + status: false, + } + } break case 'default': response = this.setDefaultTaskFunction(taskFunctionProperties.name) diff --git a/src/worker/cluster-worker.ts b/src/worker/cluster-worker.ts index e6ffe0e2..e01e54e5 100644 --- a/src/worker/cluster-worker.ts +++ b/src/worker/cluster-worker.ts @@ -35,7 +35,7 @@ export class ClusterWorker< /** * Constructs a new poolifier cluster worker. - * @param taskFunctions - Task function(s) processed by the worker when the pool's `execution` function is invoked. + * @param taskFunctions - Task function(s) processed by the worker when the pool's `execute` method is invoked. * @param opts - Options for the worker. */ public constructor ( diff --git a/src/worker/thread-worker.ts b/src/worker/thread-worker.ts index 85ec8681..82305d3f 100644 --- a/src/worker/thread-worker.ts +++ b/src/worker/thread-worker.ts @@ -45,7 +45,7 @@ export class ThreadWorker< /** * Constructs a new poolifier thread worker. - * @param taskFunctions - Task function(s) processed by the worker when the pool's `execution` function is invoked. + * @param taskFunctions - Task function(s) processed by the worker when the pool's `execute` method is invoked. * @param opts - Options for the worker. */ public constructor ( -- 2.34.1