1 import type { IPoolWorker
} from
'../pool-worker'
2 import { AbstractWorkerChoiceStrategy
} from
'./abstract-worker-choice-strategy'
5 * Selects the next worker in a round robin fashion.
7 * @typeParam Worker - Type of worker which manages the strategy.
8 * @typeParam Data - Type of data sent to the worker. This can only be serializable data.
9 * @typeParam Response - Type of response of execution. This can only be serializable data.
11 export class RoundRobinWorkerChoiceStrategy
<
12 Worker
extends IPoolWorker
,
15 > extends AbstractWorkerChoiceStrategy
<Worker
, Data
, Response
> {
17 * Index for the next worker.
19 private nextWorkerIndex
: number = 0
22 public reset (): boolean {
23 this.nextWorkerIndex
= 0
28 public choose (): Worker
{
29 const chosenWorker
= this.pool
.workers
[this.nextWorkerIndex
]
30 this.nextWorkerIndex
=
31 this.nextWorkerIndex
=== this.pool
.workers
.length
- 1
33 : this.nextWorkerIndex
+ 1