## [Unreleased]
+### Fixed
+
+- Fix typescript type definition for worker function: ensure the input data is optional.
+- Fix typescript type definition for pool execute(): ensure the input data is optional.
+
## [2.4.9] - 2023-04-15
### Added
tasksQueueOptions?: TasksQueueOptions
): void {
if (this.opts.enableTasksQueue === true && !enable) {
- for (const [workerNodeKey] of this.workerNodes.entries()) {
- this.flushTasksQueue(workerNodeKey)
- }
+ this.flushTasksQueues()
}
this.opts.enableTasksQueue = enable
this.setTasksQueueOptions(tasksQueueOptions as TasksQueueOptions)
}
/** @inheritDoc */
- public async execute (data: Data): Promise<Response> {
+ public async execute (data?: Data): Promise<Response> {
const [workerNodeKey, workerNode] = this.chooseWorkerNode()
const submittedTask: Task<Data> = {
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
const workerNodeKey = this.getWorkerNodeKey(worker)
this.flushTasksQueue(workerNodeKey)
}
+
+ private flushTasksQueues (): void {
+ for (const [workerNodeKey] of this.workerNodes.entries()) {
+ this.flushTasksQueue(workerNodeKey)
+ }
+ }
}
*/
findFreeWorkerNodeKey: () => number
/**
- * Executes the function specified in the constructor with the task data input parameter.
+ * Executes the function specified in the worker constructor with the task data input parameter.
*
- * @param data - The task input data for the specified function. This can only be serializable data.
- * @returns Promise that will be resolved when the task is successfully completed.
+ * @param data - The task input data for the specified worker function. This can only be serializable data.
+ * @returns Promise that will be fulfilled when the task is completed.
*/
- execute: (data: Data) => Promise<Response>
+ execute: (data?: Data) => Promise<Response>
/**
* Shutdowns every current worker in this pool.
*/
/** @inheritDoc */
protected registerWorkerMessageListener<Message extends Data | Response>(
- messageChannel: ThreadWorkerWithMessageChannel,
+ worker: ThreadWorkerWithMessageChannel,
listener: (message: MessageValue<Message>) => void
): void {
- messageChannel.port2?.on('message', listener)
+ worker.port2?.on('message', listener)
}
/** @inheritDoc */