X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fworker%2Fthread-worker.ts;h=e133430f5029813aaac582c1a7156f053293d75f;hb=fa548cda5120ac0708d82f37cd0ce1260d7f96c1;hp=7b92caf67201795797f6e3e06fff4fc593f4ee94;hpb=76b178d95efa0dc23addd65ab87e94736f1ed23a;p=poolifier.git diff --git a/src/worker/thread-worker.ts b/src/worker/thread-worker.ts index 7b92caf6..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( - 'worker-thread-pool:poolifier', - 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 }