Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • O openapi-generator
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 3,476
    • Issues 3,476
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 402
    • Merge requests 402
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • OpenAPI Tools
  • openapi-generator
  • Issues
  • #14415
Closed
Open
Issue created Jan 10, 2023 by Administrator@rootContributor

[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

Assignee
Assign to
Time tracking