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