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

Lifetime.observeEnded and take(during:) fix. #229

Merged
merged 3 commits into from
Feb 18, 2017
Merged

Lifetime.observeEnded and take(during:) fix. #229

merged 3 commits into from
Feb 18, 2017

Conversation

andersio
Copy link
Member

@andersio andersio commented Jan 14, 2017

  1. New methods and operator: attach, observeEnded and +=.

    ended provides a full Signal interface that is overblown for the general use cases of Lifetime.

  2. [Bugfix?] Safe observation & deprecating Lifetime.ended.

    ended.observeCompleted does not handle the observations to a terminated ended Signal, and the action is simply ignored.

    It should have been invoked regardless, like how adding a Disposable to disposed CompositeDisposable would dispose of the disposable being added.

    Composition of Lifetime is suggested to be done through lifetime operators instead, e.g. and and or, should the demand arise.

@andersio andersio changed the title Lifetime observation shorthands. Lifetime observation shorthands + Refactoring. Jan 14, 2017
@andersio andersio force-pushed the lifetime-api branch 4 times, most recently from 51c17b2 to d3ecd73 Compare January 14, 2017 17:56
@andersio andersio changed the title Lifetime observation shorthands + Refactoring. Lifetime observation shorthands + Fix for ended lifetime. Jan 14, 2017
@andersio andersio added the bug label Jan 15, 2017
@sharplet
Copy link
Contributor

I think I'm 👍 on attach and observeEnded, although I think attach could use a more descriptive name. But I think adding += would be a step backwards in terms of clarity.

import Result

final class LifetimeSpec: QuickSpec {
override func spec() {
describe("Lifetime") {
it("should complete its lifetime ended signal when the it deinitializes") {
let object = MutableReference(TestObject())
describe("ended") {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a nitpick, but do you think we can make this change without reindenting the file? It makes the diff a little hard to follow, and there's no shared setup/teardown code.

@mdiep
Copy link
Contributor

mdiep commented Jan 25, 2017

I really like the simplicity of exposing ended: Signal<(), NoError>. Clear, unambiguous, and does very little to expand the API. I also think we should prefer Signals to Disposables.

If we're concerned about the safety issue you mentioned, adding the terminated events to Observer seems like a fine approach.

@inamiy
Copy link
Contributor

inamiy commented Jan 25, 2017

I'm +1 for not exposing ended: Signal<(), NoError>.
It's hard to grasp from the type that only ended.observeCompleted { ... } will work.

But I don't get why disposable is needed as an argument of func attach.
I think just plain () -> () is sufficient.
(lifetime.observeEnded seems enough to take () -> (), and maybe attach is overkill)

Also, I don't think Observer(terminated:) is necessary because end only does sendCompleted.
(Is there any chance of sendInterrupted or others?)

P.S. I think Signal<Never, NoError> describes a bit better than Signal<(), NoError>.

@andersio
Copy link
Member Author

@inamiy When the lifetime has already terminated.

@andersio
Copy link
Member Author

andersio commented Jan 25, 2017

@mdiep #143 might have a stake in this, if it is still on the table. #143 also touches on where += might make sense, though it is purely sugar.

@inamiy
Copy link
Contributor

inamiy commented Jan 25, 2017

@andersio
Ah, you are right. Lifetime may sendInterrupted.
And with #143, I got the idea of func attach.

@mdiep
Copy link
Contributor

mdiep commented Jan 29, 2017

I still prefer ended: Signal<(), NoError>.

I can be 👍 to observeEnded if people find ended confusing.

But I'd prefer not to add attach or +=. I think that muddles the job of Lifetime—which should be just to notify observers when the lifetime has ended. I don't think we should give Lifetime any knowledge of Disposable.

@andersio
Copy link
Member Author

andersio commented Jan 29, 2017

I don't quite see the problem here. We can just treat a fire-exactly-once Disposable as a termination observer. They are all a () -> Void sink anyway...

@mdiep
Copy link
Contributor

mdiep commented Jan 29, 2017

Yeah, so I think writing lifetime.observeEnded(disposable.dispose) is fine. I don't think it requires extra sugar that couples the two concepts.

@andersio andersio force-pushed the lifetime-api branch 3 times, most recently from 1cfcf00 to 3b938ba Compare January 30, 2017 19:45
@andersio andersio force-pushed the lifetime-api branch 3 times, most recently from d766c06 to 3a5bafa Compare February 17, 2017 09:18
@andersio andersio changed the title Lifetime observation shorthands + Fix for ended lifetime. Lifetime.observeEnded and take(during:) fix. Feb 17, 2017
@andersio
Copy link
Member Author

The deprecation of ended is reverted, while observeEnded is documented as the preferred API unless composition is needed.

@andersio andersio removed the bug label Feb 17, 2017
Copy link
Contributor

@sharplet sharplet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@@ -1,6 +1,6 @@
import Quick
import Nimble
import ReactiveSwift
@testable import ReactiveSwift
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this still need to be @testable?

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.

4 participants