X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;ds=sidebyside;f=src%2Fworker%2Fthread-worker.ts;h=bc143a1f914b7e7dba14b395ac456be40c59ed80;hb=00e1bdeb5c50b0eede8fe2f72d47bf8992e4aede;hp=d5ce3a2f130da3efbe81f0aa0e3b3e7394033822;hpb=34d8846f1e7e54273f3944f687336c5624a18f39;p=poolifier.git diff --git a/src/worker/thread-worker.ts b/src/worker/thread-worker.ts index d5ce3a2f..bc143a1f 100644 --- a/src/worker/thread-worker.ts +++ b/src/worker/thread-worker.ts @@ -30,7 +30,8 @@ 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 +42,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,8 +81,10 @@ 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 }) } /**