UNPKG

@duongtrungnguyen/nestro

Version:
49 lines 1.72 kB
var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __hasOwnProp = Object.prototype.hasOwnProperty; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); var round_robin_strategy_exports = {}; __export(round_robin_strategy_exports, { RoundRobinStrategy: () => RoundRobinStrategy }); module.exports = __toCommonJS(round_robin_strategy_exports); 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(); } } // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { RoundRobinStrategy }); //# sourceMappingURL=round-robin.strategy.js.map