X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fworker%2Fthread-worker.ts;h=638de2ba2f9c8f090360c528cd1169cfcd52e823;hb=4335b463013675c6f5f0cd49c86ba7c75cb59c76;hp=756550e3337d1e8ef66071dd6dd21c77a5679f45;hpb=9b5c72ff77584e1e2610710b66261eb31dabb954;p=poolifier.git diff --git a/src/worker/thread-worker.ts b/src/worker/thread-worker.ts index 756550e3..638de2ba 100644 --- a/src/worker/thread-worker.ts +++ b/src/worker/thread-worker.ts @@ -4,10 +4,10 @@ import { parentPort, threadId } from 'node:worker_threads' -import type { MessageValue } from '../utility-types' -import { AbstractWorker } from './abstract-worker' -import type { WorkerOptions } from './worker-options' -import type { TaskFunction, TaskFunctions } from './task-functions' +import type { MessageValue } from '../utility-types.js' +import { AbstractWorker } from './abstract-worker.js' +import type { WorkerOptions } from './worker-options.js' +import type { TaskFunction, TaskFunctions } from './task-functions.js' /** * A thread worker used by a poolifier `ThreadPool`. @@ -31,6 +31,7 @@ export class ThreadWorker< * Message port used to communicate with the main worker. */ private port?: MessagePort + /** * Constructs a new poolifier thread worker. * @@ -41,7 +42,7 @@ export class ThreadWorker< taskFunctions: TaskFunction | TaskFunctions, opts: WorkerOptions = {} ) { - super(isMainThread, parentPort as MessagePort, taskFunctions, opts) + super(isMainThread, parentPort, taskFunctions, opts) } /** @inheritDoc */ @@ -80,8 +81,13 @@ 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 + } satisfies MessageValue) } /**