* Reduces a list of servers to ensure they fall within an acceptable latency window. This is * further specified in the "Server Selection" specification, found here: * * @see https://github.com/mongodb/specifications/blob/master/source/server-selection/server-selection.md * * @param topologyDes
( topologyDescription: TopologyDescription, servers: ServerDescription[] )
| 241 | * @returns The servers which fall within an acceptable latency window |
| 242 | */ |
| 243 | function latencyWindowReducer( |
| 244 | topologyDescription: TopologyDescription, |
| 245 | servers: ServerDescription[] |
| 246 | ): ServerDescription[] { |
| 247 | const low = servers.reduce( |
| 248 | (min: number, server: ServerDescription) => Math.min(server.roundTripTime, min), |
| 249 | Infinity |
| 250 | ); |
| 251 | |
| 252 | const high = low + topologyDescription.localThresholdMS; |
| 253 | return servers.filter(server => server.roundTripTime <= high && server.roundTripTime >= low); |
| 254 | } |
| 255 | |
| 256 | // filters |
| 257 | function primaryFilter(server: ServerDescription): boolean { |
no test coverage detected