Skip to content

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

Open
jpalten wants to merge 2 commits intoFrugghi:masterfrom
jpalten:proposition/return-self
Open

Add return self to methods with completion closure that already had…#17
jpalten wants to merge 2 commits intoFrugghi:masterfrom
jpalten:proposition/return-self

Conversation

@jpalten
Copy link
Copy Markdown
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
Copy Markdown
Owner

Frugghi commented Sep 5, 2018

What's the use case for this?

@jpalten
Copy link
Copy Markdown
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