mirror of
https://github.com/Ranchero-Software/NetNewsWire.git
synced 2025-01-09 00:13:45 +01:00
Add async await version of downloadUsingCache.
This commit is contained in:
parent
76fffca825
commit
0a626b1904
@ -183,6 +183,28 @@ private struct CallbackRecord {
|
||||
}
|
||||
}
|
||||
|
||||
public struct DownloadData: Sendable {
|
||||
|
||||
public let data: Data?
|
||||
public let response: URLResponse?
|
||||
}
|
||||
|
||||
@MainActor public func downloadUsingCache(_ url: URL) async throws -> DownloadData {
|
||||
|
||||
precondition(Thread.isMainThread)
|
||||
|
||||
return try await withCheckedThrowingContinuation { continuation in
|
||||
downloadUsingCache(url) { data, response, error in
|
||||
if let error {
|
||||
continuation.resume(throwing: error)
|
||||
} else {
|
||||
let downloadData = DownloadData(data: data, response: response)
|
||||
continuation.resume(returning: downloadData)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@MainActor public func downloadUsingCache(_ url: URL, _ completion: @escaping OneShotDownloadCallback) {
|
||||
precondition(Thread.isMainThread)
|
||||
DownloadWithCacheManager.shared.download(url, completion)
|
||||
|
Loading…
Reference in New Issue
Block a user