* Uses the load-balancing policies to get the relative distance to the host and return the closest one. * @param {Host} host
(host)
| 179 | * @param {Host} host |
| 180 | */ |
| 181 | getDistance(host) { |
| 182 | let distance = types.distance.ignored; |
| 183 | // this is performance critical: we can't use any other language features than for-loop :( |
| 184 | for (let i = 0; i < this._loadBalancingPolicies.length; i++) { |
| 185 | const d = this._loadBalancingPolicies[i].getDistance(host); |
| 186 | if (d < distance) { |
| 187 | distance = d; |
| 188 | if (distance === types.distance.local) { |
| 189 | break; |
| 190 | } |
| 191 | } |
| 192 | } |
| 193 | |
| 194 | host.setDistance(distance); |
| 195 | return distance; |
| 196 | } |
| 197 | |
| 198 | /** |
| 199 | * @param {String|ExecutionProfile} name |
no test coverage detected