(upstream)
| 8705 | this[kOptions] = opts; |
| 8706 | this[kIndex] = -1; |
| 8707 | this[kCurrentWeight] = 0; |
| 8708 | this[kMaxWeightPerServer] = this[kOptions].maxWeightPerServer || 100; |
| 8709 | this[kErrorPenalty] = this[kOptions].errorPenalty || 15; |
| 8710 | if (!Array.isArray(upstreams)) { |
| 8711 | upstreams = [upstreams]; |
| 8712 | } |
| 8713 | if (typeof factory !== "function") { |
| 8714 | throw new InvalidArgumentError("factory must be a function."); |
| 8715 | } |
| 8716 | this[kInterceptors] = ((_a2 = opts.interceptors) == null ? void 0 : _a2.BalancedPool) && Array.isArray(opts.interceptors.BalancedPool) ? opts.interceptors.BalancedPool : []; |
| 8717 | this[kFactory] = factory; |
| 8718 | for (const upstream of upstreams) { |
| 8719 | this.addUpstream(upstream); |
| 8720 | } |
| 8721 | this._updateBalancedPoolStats(); |
| 8722 | } |
| 8723 | addUpstream(upstream) { |
| 8724 | const upstreamOrigin = parseOrigin(upstream).origin; |
| 8725 | if (this[kClients].find((pool2) => pool2[kUrl].origin === upstreamOrigin && pool2.closed !== true && pool2.destroyed !== true)) { |
| 8726 | return this; |
| 8727 | } |
| 8728 | const pool = this[kFactory](upstreamOrigin, Object.assign({}, this[kOptions])); |
| 8729 | this[kAddClient](pool); |
| 8730 | pool.on("connect", () => { |
| 8731 | pool[kWeight] = Math.min(this[kMaxWeightPerServer], pool[kWeight] + this[kErrorPenalty]); |
| 8732 | }); |
| 8733 | pool.on("connectionError", () => { |
| 8734 | pool[kWeight] = Math.max(1, pool[kWeight] - this[kErrorPenalty]); |
| 8735 | this._updateBalancedPoolStats(); |
| 8736 | }); |
no test coverage detected