Created
May 28, 2024 03:58
-
-
Save robertmryan/ae3e566e361a096de61085565a4f1b71 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Task { | |
await withDiscardingTaskGroup { group in // or, `withTaskGroup(of: Void.self) { group in … }` | |
for destination in pingResults.keys { | |
let hostname = destination.hostname | |
group.addTask { [self] in | |
do { | |
let averagePing = try await getAveragePing(hostname: hostname, interval: 1, timeout: 2, attempts: 5) | |
pingResults[destination] = .success(averagePing) | |
processingFirstResult = false | |
} catch let error as PingError { | |
pingResults[destination] = .failure(error) | |
} catch { | |
fatalError("Unhandled error pinging: \(error)") | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment