Skip to content

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

@zhouhao27

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?

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