[REQ] [swift5] async/await `execute` interface of RequestBuilder<T>.
Created by: yosshi4486
Is your feature request related to a problem? Please describe.
A RequestBuilder<T>
class already has a closure based execute
API, however it doesn't have an async/await based API.
Adopting the async interface is more useful in some cases.
Describe the solution you'd like
Add a new async API interface to RequestBuilder<T>
, like this.
@discardableResult
func execute() async throws -> Response<T> {
return try await withTaskCancellationHandler {
try Task.checkCancellation()
return try await withCheckedThrowingContinuation { continuation in
guard !Task.isCancelled else {
continuation.resume(throwing: CancellationError())
return
}
self.execute { result in
switch result {
case let .success(response):
continuation.resume(returning: response)
case let .failure(error):
continuation.resume(throwing: error)
}
}
}
} onCancel: {
requestTask.cancel()
}
}
It should be added only when the generator passes async/await option.
Describe alternatives you've considered
None
Additional context
None