chore: v3.0.6
[poolifier.git] / src / worker / abstract-worker.ts
index 22e65bad63d213aa6b1bda6f0adc6a2a76401873..060fe63451877a96c0f26fe843c16ef2c7644f59 100644 (file)
@@ -368,13 +368,13 @@ export abstract class AbstractWorker<
    *
    * @param message - The kill message.
    */
-  protected handleKillMessage (message: MessageValue<Data>): void {
+  protected handleKillMessage (_message: MessageValue<Data>): void {
     this.stopCheckActive()
     if (isAsyncFunction(this.opts.killHandler)) {
       (this.opts.killHandler?.() as Promise<void>)
         .then(() => {
           this.sendToMainWorker({ kill: 'success' })
-          return null
+          return undefined
         })
         .catch(() => {
           this.sendToMainWorker({ kill: 'failure' })
@@ -405,7 +405,7 @@ export abstract class AbstractWorker<
   private checkMessageWorkerId (message: MessageValue<Data>): void {
     if (message.workerId == null) {
       throw new Error('Message worker id is not set')
-    } else if (message.workerId != null && message.workerId !== this.id) {
+    } else if (message.workerId !== this.id) {
       throw new Error(
         `Message worker id ${message.workerId} does not match the worker id ${this.id}`
       )
@@ -493,8 +493,8 @@ export abstract class AbstractWorker<
    */
   protected run (task: Task<Data>): void {
     const { name, taskId, data } = task
-    const fn = this.taskFunctions.get(name ?? DEFAULT_TASK_NAME)
-    if (fn == null) {
+    const taskFunctionName = name ?? DEFAULT_TASK_NAME
+    if (!this.taskFunctions.has(taskFunctionName)) {
       this.sendToMainWorker({
         workerError: {
           name: name as string,
@@ -505,6 +505,7 @@ export abstract class AbstractWorker<
       })
       return
     }
+    const fn = this.taskFunctions.get(taskFunctionName)
     if (isAsyncFunction(fn)) {
       this.runInAsyncScope(this.runAsync.bind(this), this, fn, task)
     } else {