mirror of
https://github.com/Ranchero-Software/NetNewsWire
synced 2026-12-02 18:32:55 +00:00
Add async wrapper for download(url).
This commit is contained in:
1 parent
845789f165
commit
765cd3b9e6
1 file changed
+12
@@ -43,6 +43,18 @@ public typealias DownloadCallback = @MainActor (Data?, URLResponse?, Error?) ->
|
||||
urlSession.invalidateAndCancel()
|
||||
}
|
||||
|
||||
public func download(_ url: URL) async throws -> (Data?, URLResponse?) {
|
||||
try await withCheckedThrowingContinuation { continuation in
|
||||
download(url) { data, response, error in
|
||||
if let error {
|
||||
continuation.resume(throwing: error)
|
||||
} else {
|
||||
continuation.resume(returning: (data, response))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public func download(_ url: URL, _ callback: @escaping DownloadCallback) {
|
||||
assert(Thread.isMainThread)
|
||||
download(URLRequest(url: url), callback)
|
||||
|
||||
Reference in new issue
Block a user