import type { IPoolItem, IPoolItemWithStats } from '../types'; import { AbstractPool } from './AbstractPool'; /** * Simple roundrobin */ export class RoundRobin extends AbstractPool implements IPoolItemWithStats { protected iterator: Iterator; constructor(override readonly agents: Map) { super(agents); this.stats.free = Number.POSITIVE_INFINITY; this.iterator = this.agents.values(); } getNextItem(): TValue { let next = this.iterator.next(); if (next.done) { this.iterator = this.agents.values(); next = this.iterator.next(); } return next.value; } *[Symbol.iterator](): Generator { yield this.getNextItem(); } }