import {
- type MessagePort,
isMainThread,
+ type MessagePort,
parentPort,
threadId
} from 'node:worker_threads'
+
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'
+import type { WorkerOptions } from './worker-options.js'
/**
* A thread worker used by a poolifier `ThreadPool`.
taskFunctions: TaskFunction<Data, Response> | TaskFunctions<Data, Response>,
opts: WorkerOptions = {}
) {
- super(isMainThread, parentPort as MessagePort, taskFunctions, opts)
+ super(isMainThread, parentPort, taskFunctions, opts)
}
/** @inheritDoc */
this.port.on('message', this.messageListener.bind(this))
this.sendToMainWorker({
ready: true,
- taskFunctionNames: this.listTaskFunctionNames()
+ taskFunctionsProperties: this.listTaskFunctionsProperties()
})
} catch {
this.sendToMainWorker({
ready: false,
- taskFunctionNames: this.listTaskFunctionNames()
+ taskFunctionsProperties: this.listTaskFunctionsProperties()
})
}
}
protected readonly sendToMainWorker = (
message: MessageValue<Response>
): void => {
- this.port?.postMessage({ ...message, workerId: this.id })
+ this.port?.postMessage({
+ ...message,
+ workerId: this.id
+ } satisfies MessageValue<Response>)
}
/**