X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fworker%2Fthread-worker.ts;h=e133430f5029813aaac582c1a7156f053293d75f;hb=6ff68506534dde3c585fd6a6abb299744f7002ca;hp=fdbab44ed5f1356e6502a814f56e3a94ef54215d;hpb=04212af7b1a1494ff58da58c9e5b3397d25f18b7;p=poolifier.git diff --git a/src/worker/thread-worker.ts b/src/worker/thread-worker.ts index fdbab44e..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,7 +41,7 @@ export class ThreadWorker< taskFunctions: TaskFunction | TaskFunctions, opts: WorkerOptions = {} ) { - super(isMainThread, parentPort as MessagePort, taskFunctions) + super(isMainThread, parentPort as MessagePort, taskFunctions, opts) } /** @inheritDoc */ @@ -80,8 +80,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 }) } /**