Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add return self to methods with completion closure that already had… #17

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

jpalten
Copy link
Contributor

@jpalten jpalten commented Sep 3, 2018

When adding a completion block to open/write/connect/download etc, I noticed the behaviour of chaining those commands is a little different. This fixes that problem, so adding a completion block to any of these method calls does not change other results.

Jelle Alten added 2 commits September 3, 2018 15:32
… a `return self` for their counterpart without completion closure
@Frugghi
Copy link
Owner

Frugghi commented Sep 5, 2018

What's the use case for this?

@jpalten
Copy link
Contributor Author

jpalten commented Sep 5, 2018

for example:

if I have this code:

        self.shell
            .withCallback { [unowned self] (string: String?, error: String?) in
                DispatchQueue.main.async {
                    if let string = string {
                        self.appendToTextView(string)
                    }
                    if let error = error {
                        self.appendToTextView("[ERROR] \(error)")
                    }
                }
            }
            .connect()
            .authenticate(self.authenticationChallenge)
            .open { [unowned self] (error) in
                if let error = error {
                    self.appendToTextView("[ERROR] \(error)")
                    self.textView.isEditable = false
                } else {
                    self.textView.isEditable = true
                }                
            }

If I now want to add a callback method to connect(), I cannot change the connect to this without the fix:

            }
            .connect { error in
                print("error? \(error)")
            }
            .authenticate(self.authenticationChallenge)
            .open { [unowned self] (error) in

but it needs this in the old situation:

            }
            .connect { error in
                print("error? \(error)")
            }

        self.shell
            .authenticate(self.authenticationChallenge)
            .open { [unowned self] (error) in

which I think is unfortunate.

Hope that clarifies the use case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants