docs: add changelog entry
[poolifier.git] / src / worker / abstract-worker.ts
index 25be4820a0e8c59faa8917e0a809633c0d97de83..6e17c9ed92f53a3612d214f782d38019875ed46c 100644 (file)
@@ -36,6 +36,10 @@ export abstract class AbstractWorker<
   Data = unknown,
   Response = unknown
 > extends AsyncResource {
+  /**
+   * Worker id.
+   */
+  protected abstract id: number
   /**
    * Task function(s) processed by the worker when the pool's `execution` function is invoked.
    */
@@ -202,7 +206,7 @@ export abstract class AbstractWorker<
    * Handles an error and convert it to a string so it can be sent back to the main worker.
    *
    * @param e - The error raised by the worker.
-   * @returns Message of the error.
+   * @returns The error message.
    */
   protected handleError (e: Error | string): string {
     return e as string
@@ -225,6 +229,7 @@ export abstract class AbstractWorker<
       this.sendToMainWorker({
         data: res,
         taskPerformance,
+        workerId: this.id,
         id: message.id
       })
     } catch (e) {
@@ -234,6 +239,7 @@ export abstract class AbstractWorker<
           message: err,
           data: message.data
         },
+        workerId: this.id,
         id: message.id
       })
     } finally {
@@ -258,6 +264,7 @@ export abstract class AbstractWorker<
         this.sendToMainWorker({
           data: res,
           taskPerformance,
+          workerId: this.id,
           id: message.id
         })
         return null
@@ -269,6 +276,7 @@ export abstract class AbstractWorker<
             message: err,
             data: message.data
           },
+          workerId: this.id,
           id: message.id
         })
       })