build(deps-dev): apply updates
[poolifier.git] / src / worker / abstract-worker.ts
index 9b9ded5e9d1cc1267846fb9e0279d88de405262f..ebbefc75ba4cc8c4e09bcc3073e372085466c181 100644 (file)
@@ -78,7 +78,6 @@ export abstract class AbstractWorker<
   /**
    * Handler id of the `activeInterval` worker activity check.
    */
-  // eslint-disable-next-line no-undef
   protected activeInterval?: NodeJS.Timeout
 
   /**
@@ -355,9 +354,10 @@ export abstract class AbstractWorker<
     switch (taskFunctionOperation) {
       case 'add':
         response = this.addTaskFunction(taskFunctionProperties.name, {
-          // eslint-disable-next-line no-new-func
+          // eslint-disable-next-line @typescript-eslint/no-implied-eval, no-new-func
           taskFunction: new Function(
-            `return ${taskFunction}`
+            // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
+            `return ${taskFunction!}`
           )() as TaskFunction<Data, Response>,
           ...(taskFunctionProperties.priority != null && {
             priority: taskFunctionProperties.priority,
@@ -377,15 +377,16 @@ export abstract class AbstractWorker<
         response = { status: false, error: new Error('Unknown task operation') }
         break
     }
+    const { status, error } = response
     this.sendToMainWorker({
       taskFunctionOperation,
-      taskFunctionOperationStatus: response.status,
+      taskFunctionOperationStatus: status,
       taskFunctionProperties,
-      ...(!response.status &&
-        response.error != null && {
+      ...(!status &&
+        error != null && {
         workerError: {
           name: taskFunctionProperties.name,
-          message: this.handleError(response.error as Error | string),
+          message: this.handleError(error as Error | string),
         },
       }),
     })
@@ -398,7 +399,7 @@ export abstract class AbstractWorker<
   protected handleKillMessage (message: MessageValue<Data>): void {
     this.stopCheckActive()
     if (isAsyncFunction(this.opts.killHandler)) {
-      ;(this.opts.killHandler() as Promise<void>)
+      ;(this.opts.killHandler as () => Promise<void>)()
         .then(() => {
           this.sendToMainWorker({ kill: 'success' })
           return undefined
@@ -408,7 +409,7 @@ export abstract class AbstractWorker<
         })
     } else {
       try {
-        this.opts.killHandler?.()
+        ;(this.opts.killHandler as (() => void) | undefined)?.()
         this.sendToMainWorker({ kill: 'success' })
       } catch {
         this.sendToMainWorker({ kill: 'failure' })
@@ -426,7 +427,7 @@ export abstract class AbstractWorker<
       throw new Error('Message worker id is not set')
     } else if (message.workerId !== this.id) {
       throw new Error(
-        `Message worker id ${message.workerId} does not match the worker id ${this.id}`
+        `Message worker id ${message.workerId.toString()} does not match the worker id ${this.id.toString()}`
       )
     }
   }
@@ -514,7 +515,8 @@ export abstract class AbstractWorker<
         workerError: {
           // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
           name: name!,
-          message: `Task function '${name}' not found`,
+          // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
+          message: `Task function '${name!}' not found`,
           data,
         },
         taskId,