Skip to content

Promise chaining base on condition #1185

@zhouhao27

Description

@zhouhao27

In most case, there is only one error catch and chain for the successful operation. But for my case, what I want to do is if the operation success, then I'll return. If it's failed, I'll do another operation. Is it possible and how to express it in PromiseKit?

For example, how to convert this pseudo code to PromiseKit way?

    fetchData1(fromURL: "someURL") { (response, results, error) in
            switch response {
            case .success:
                if !data.isEmpty() {
                   // complete
                } else {
                    fetchData2(for: results) { (response, results, error) in
                        switch response {
                        case .success:
                            // complete
                        }
                    case .fail:
                            // complete with error
                    }
             }
            case .fail:
                    fetchData2(for: results) { (response, results, error) in
                        switch response {
                        case .success:
                            // complete
                        }
                    case .fail:
                            // complete with error
                    }        
            }
        }

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