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 * Id of the next worker.
19 private nextWorkerId
: number = 0
22 public reset (): boolean {
28 public choose (): Worker
{
29 const chosenWorker
= this.pool
.workers
.get(this.nextWorkerId
)
32 this.nextWorkerId
=== this.pool
.workers
.size
- 1
34 : this.nextWorkerId
+ 1