Add async wrapper for download(url).

This commit is contained in:
Brent Simmons committed 2025-11-09 10:44:32 -08:00
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)