isMainThread,
type MessagePort,
parentPort,
- threadId
+ threadId,
} from 'node:worker_threads'
import type { MessageValue } from '../utility-types.js'
*
* If you use a `DynamicThreadPool` the extra workers that were created will be terminated,
* but the minimum number of workers will be guaranteed.
- *
* @typeParam Data - Type of data this worker receives from pool's execution. This can only be structured-cloneable data.
* @typeParam Response - Type of response the worker sends back to the main thread. This can only be structured-cloneable data.
* @author [Alessandro Pio Ardizio](https://github.com/pioardi)
/**
* Constructs a new poolifier thread worker.
- *
* @param taskFunctions - Task function(s) processed by the worker when the pool's `execution` function is invoked.
* @param opts - Options for the worker.
*/
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(),
})
}
}
): void => {
this.port?.postMessage({
...message,
- workerId: this.id
+ workerId: this.id,
} satisfies MessageValue<Response>)
}
/**
* @inheritDoc
- * @override
*/
protected handleError (error: Error | string): string {
return error as string