func determineRemoteServer()

in Sources/XCRemoteCache/Network/NetworkServerProbe.swift [57:75]


    func determineRemoteServer() throws -> URL {
        let fastest: (URL?, TimeInterval) = servers.reduce(
            (nil, TimeInterval.greatestFiniteMagnitude)
        ) { prev, serverURL in
            let probeURL = serverURL.appendingPathComponent(healthPath)
            do {
                let minDuration = try (0..<probes).map { _ -> TimeInterval in
                    let start = Date()
                    _ = try networkClient.fileExistsSynchronously(probeURL)
                    return Date().timeIntervalSince(start)
                }.min() ?? 0
                if minDuration < prev.1 {
                    return (serverURL, minDuration)
                }
            } catch {
                // don't consider that server if the request failed (e.g. no VPN access)
            }
            return prev
        }