/** @inheritDoc */
public async execute (data?: Data, name?: string): Promise<Response> {
- const [workerNodeKey, workerNode] = this.chooseWorkerNode()
+ const workerNodeKey = this.chooseWorkerNode()
const submittedTask: Task<Data> = {
name,
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
this.promiseResponseMap.set(submittedTask.id as string, {
resolve,
reject,
- worker: workerNode.worker
+ worker: this.workerNodes[workerNodeKey].worker
})
})
if (
/**
* Chooses a worker node for the next task.
*
- * The default uses a round robin algorithm to distribute the load.
+ * The default worker choice strategy uses a round robin algorithm to distribute the load.
*
- * @returns [worker node key, worker node].
+ * @returns The worker node key
*/
- protected chooseWorkerNode (): [number, WorkerNode<Worker, Data>] {
+ protected chooseWorkerNode (): number {
let workerNodeKey: number
if (this.type === PoolType.DYNAMIC && !this.full && this.internalBusy()) {
const workerCreated = this.createAndSetupWorker()
} else {
workerNodeKey = this.workerChoiceStrategyContext.execute()
}
- return [workerNodeKey, this.workerNodes[workerNodeKey]]
+ return workerNodeKey
}
/**
)
let results = new Set()
for (let i = 0; i < max; i++) {
- results.add(pool.chooseWorkerNode()[1].worker.id)
+ results.add(pool.workerNodes[pool.chooseWorkerNode()].worker.id)
}
expect(results.size).toBe(max)
await pool.destroy()
)
results = new Set()
for (let i = 0; i < max; i++) {
- results.add(pool.chooseWorkerNode()[1].worker.threadId)
+ results.add(pool.workerNodes[pool.chooseWorkerNode()].worker.threadId)
}
expect(results.size).toBe(max)
await pool.destroy()