mirror of
https://github.com/Ranchero-Software/NetNewsWire.git
synced 2025-02-03 12:27:32 +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) {
|
@MainActor public func downloadUsingCache(_ url: URL, _ completion: @escaping OneShotDownloadCallback) {
|
||||||
precondition(Thread.isMainThread)
|
precondition(Thread.isMainThread)
|
||||||
DownloadWithCacheManager.shared.download(url, completion)
|
DownloadWithCacheManager.shared.download(url, completion)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user