X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fworker%2Fabstract-worker.ts;h=6e17c9ed92f53a3612d214f782d38019875ed46c;hb=e5b3047de23abe2d273ad39335230b87a68a0fe5;hp=25be4820a0e8c59faa8917e0a809633c0d97de83;hpb=3749facbef3139d185918f89b1e29c69fc02015f;p=poolifier.git diff --git a/src/worker/abstract-worker.ts b/src/worker/abstract-worker.ts index 25be4820..6e17c9ed 100644 --- a/src/worker/abstract-worker.ts +++ b/src/worker/abstract-worker.ts @@ -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 }) })