Skip to content

How to convert a function with complete handler to async/await #55

Description

@zhouhao27

I have a function:

func find(name: String, complete: (([Result])->Void))

I want to convert to a function something like this:

func find(name: String) -> Promise<Element?> {
        find(name: name) {
            (result) in
            switch result {
            case .success(let elements):
                if let element = elements {
                    // ??? How to return the element
                }
            case .failure(let error):
                print(error)
                // ??? How to return nil
            }
        }
}

The example is really simple one. Can AwaitKit used for the case like my example?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions