Skip to content

Instantly share code, notes, and snippets.

@robertmryan
Created May 28, 2024 03:58
Show Gist options
  • Save robertmryan/ae3e566e361a096de61085565a4f1b71 to your computer and use it in GitHub Desktop.
Save robertmryan/ae3e566e361a096de61085565a4f1b71 to your computer and use it in GitHub Desktop.
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