As your answer, I resolve this issue like this.
This code download all web url file to local cache.
And check total and completed number of them.
private static func downloadAllFilesAsync(_ medicalInfo: MedicalInfo)
async throws -> (total: Int, completed: Int) {
...
let download: (URL) async throws -> Int = { url in
do {
_ = try await WWW.downloadFileAsync(url)
return 1
} catch {
throw error
}
}
return try await withThrowingTaskGroup(of: Int.self) {
group -> (Int, Int) in
buildURLSet() // To be requested url array ([URL]) is set.
let total = requested.count
var completed = 0
for requestUrl in requested {
group.addTask {
return try await download(requestUrl)
}
}
completed = try await group.reduce(0, +)
return (total, completed)
}
}
Topic:
App & System Services
SubTopic:
Processes & Concurrency
Tags: