*/
export class RoundRobinWorkerChoiceStrategy<
Worker extends IPoolWorker,
- Data,
- Response
+ Data = unknown,
+ Response = unknown
>
extends AbstractWorkerChoiceStrategy<Worker, Data, Response>
implements IWorkerChoiceStrategy {
*/
private nextWorkerId: number = 0
- /** {@inheritDoc} */
+ /** @inheritDoc */
public reset (): boolean {
this.nextWorkerId = 0
return true
}
- /** {@inheritDoc} */
+ /** @inheritDoc */
public choose (): number {
const chosenWorkerKey = this.nextWorkerId
this.nextWorkerId =
return chosenWorkerKey
}
- /** {@inheritDoc} */
+ /** @inheritDoc */
public remove (workerKey: number): boolean {
if (this.nextWorkerId === workerKey) {
- this.nextWorkerId =
- this.nextWorkerId > this.pool.workers.length - 1
- ? this.pool.workers.length - 1
- : this.nextWorkerId
+ if (this.pool.workers.length === 0) {
+ this.nextWorkerId = 0
+ } else {
+ this.nextWorkerId =
+ this.nextWorkerId > this.pool.workers.length - 1
+ ? this.pool.workers.length - 1
+ : this.nextWorkerId
+ }
}
return true
}