X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fworker%2Fthread-worker.ts;h=e133430f5029813aaac582c1a7156f053293d75f;hb=6ff68506534dde3c585fd6a6abb299744f7002ca;hp=bfd1c13cdb41775c0c01d031cb0aedf9d364959b;hpb=25926072f5397949802f6af5a2f7d49d6f15cacc;p=poolifier.git diff --git a/src/worker/thread-worker.ts b/src/worker/thread-worker.ts index bfd1c13c..e133430f 100644 --- a/src/worker/thread-worker.ts +++ b/src/worker/thread-worker.ts @@ -30,7 +30,7 @@ export class ThreadWorker< /** * Message port used to communicate with the main worker. */ - private port!: MessagePort + private port?: MessagePort /** * Constructs a new poolifier thread worker. * @@ -41,13 +41,7 @@ export class ThreadWorker< taskFunctions: TaskFunction | TaskFunctions, opts: WorkerOptions = {} ) { - super( - 'poolifier:thread-worker', - isMainThread, - parentPort as MessagePort, - taskFunctions, - opts - ) + super(isMainThread, parentPort as MessagePort, taskFunctions, opts) } /** @inheritDoc */ @@ -86,11 +80,16 @@ export class ThreadWorker< } /** @inheritDoc */ - protected sendToMainWorker (message: MessageValue): void { - this.port.postMessage({ ...message, workerId: this.id }) + protected readonly sendToMainWorker = ( + message: MessageValue + ): void => { + this.port?.postMessage({ ...message, workerId: this.id }) } - /** @inheritDoc */ + /** + * @inheritDoc + * @override + */ protected handleError (error: Error | string): string { return error as string }