+ 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(
+ `return ${taskFunction}`
+ )() as TaskFunction<Data, Response>,
+ ...(taskFunctionProperties.priority != null && {
+ priority: taskFunctionProperties.priority
+ }),
+ ...(taskFunctionProperties.strategy != null && {
+ strategy: taskFunctionProperties.strategy
+ })
+ })
+ break
+ case 'remove':
+ response = this.removeTaskFunction(taskFunctionProperties.name)
+ break
+ case 'default':
+ response = this.setDefaultTaskFunction(taskFunctionProperties.name)
+ break
+ default:
+ response = { status: false, error: new Error('Unknown task operation') }
+ break
+ }
+ this.sendToMainWorker({
+ taskFunctionOperation,
+ taskFunctionOperationStatus: response.status,
+ taskFunctionProperties,
+ ...(!response.status &&
+ response.error != null && {
+ workerError: {
+ name: taskFunctionProperties.name,
+ message: this.handleError(response.error as Error | string)
+ }
+ })
+ })