Adopting async/await
Closed this issue · 0 comments
corysullivan commented
What are your thoughts on adding an async/await option? Would you consider a PR with sonething like the following?
@available(iOS 15, macOS 12.0, watchOS 8, tvOS 15, *)
public extension URLSession {
func load<A>(_ e: Endpoint<A>) async throws -> A {
let request = e.request
let (data, resp) = try await data(for: request)
guard let h = resp as? HTTPURLResponse else {
throw UnknownError()
}
guard e.expectedStatusCode(h.statusCode) else {
throw WrongStatusCodeError(statusCode: h.statusCode, response: h, responseBody: data)
}
return try e.parse(data, resp).get()
}
}