UNPKG

@duongtrungnguyen/nestro

Version:
26 lines 668 B
class RoundRobinStrategy { constructor() { this.counters = /* @__PURE__ */ new Map(); } selectInstance(instances) { if (!instances || instances.length === 0) { return null; } if (instances.length === 1) { return instances[0]; } const serviceName = instances[0].name; let counter = this.counters.get(serviceName) || 0; const instance = instances[counter % instances.length]; counter = (counter + 1) % instances.length; this.counters.set(serviceName, counter); return instance; } reset() { this.counters.clear(); } } export { RoundRobinStrategy }; //# sourceMappingURL=round-robin.strategy.js.map