docs: fix API documentation
[poolifier.git] / src / worker / abstract-worker.ts
index 1b34fb139dd7d0d6513a298be184c5c342d8bcef..64627efb8823198c6cb09c81fbdded3bef046f01 100644 (file)
@@ -243,7 +243,7 @@ export abstract class AbstractWorker<
    * @returns The names of the worker's task functions.
    */
   public listTaskFunctions (): string[] {
-    return Array.from(this.taskFunctions.keys())
+    return [...this.taskFunctions.keys()]
   }
 
   /**
@@ -293,7 +293,9 @@ export abstract class AbstractWorker<
    * @param message - The received message.
    */
   protected messageListener (message: MessageValue<Data>): void {
-    if (message.workerId === this.id) {
+    if (message.workerId != null && message.workerId !== this.id) {
+      throw new Error('Message worker id does not match worker id')
+    } else if (message.workerId === this.id) {
       if (message.statistics != null) {
         // Statistics message received
         this.statistics = message.statistics
@@ -302,7 +304,7 @@ export abstract class AbstractWorker<
         !this.isMain && message.checkActive
           ? this.startCheckActive()
           : this.stopCheckActive()
-      } else if (message.id != null && message.data != null) {
+      } else if (message.taskId != null && message.data != null) {
         // Task message received
         this.run(message)
       } else if (message.kill === true) {
@@ -422,7 +424,7 @@ export abstract class AbstractWorker<
         data: res,
         taskPerformance,
         workerId: this.id,
-        id: task.id
+        taskId: task.taskId
       })
     } catch (e) {
       const errorMessage = this.handleError(e as Error | string)
@@ -433,7 +435,7 @@ export abstract class AbstractWorker<
           data: task.data
         },
         workerId: this.id,
-        id: task.id
+        taskId: task.taskId
       })
     } finally {
       this.updateLastTaskTimestamp()
@@ -458,7 +460,7 @@ export abstract class AbstractWorker<
           data: res,
           taskPerformance,
           workerId: this.id,
-          id: task.id
+          taskId: task.taskId
         })
         return null
       })
@@ -471,7 +473,7 @@ export abstract class AbstractWorker<
             data: task.data
           },
           workerId: this.id,
-          id: task.id
+          taskId: task.taskId
         })
       })
       .finally(() => {