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

Added a failing test to illustrate bug in SignalProducer.sampleOn(SignalProducer) #2560

Closed
wants to merge 1 commit into from

Conversation

NachoSoto
Copy link
Member

The docs read "If sampler fires before a value has been observed on self, nothing happens.".
However, in this case the sampler "fires" synchronously upon subscription. Thus, I don't think this is the expected behavior.

If I change the test slightly:

let sampler = SignalProducer<(), NoError>(value: ())
    .delay(0.1, onScheduler: QueueScheduler())

let result = producer.sampleOn(sampler)

var valueReceived: Int?
result.startWithNext { valueReceived = $0 }

expect(valueReceived).toEventually(equal(1))

Then the test passes. So adding a small delay to introduce a scheduler jump is a workaround.

…nalProducer)

The docs read "If `sampler` fires before a value has been observed on `self`, nothing happens.".
However, in this case the sampler "fires" synchronously upon subscription. Thus, I don't think this is the expected behavior.
@NachoSoto NachoSoto added this to the 4.0 milestone Nov 19, 2015
@neilpa
Copy link
Member

neilpa commented Nov 19, 2015

The gist of the problem is that sampleOn is implemented with lift which is effectively right-biased over it's operands. This means sampler starts and completes before the sampled producer when it's synchronous.

@NachoSoto
Copy link
Member Author

@neilpa that makes sense.
That reminds me of the commend I added to lift:

/// Note: starting the returned producer will start the receiver of the operator,
/// which may not be adviseable for some operators.

I haven't thought much about it, but there might be a way to fix this by having a slightly different version of lift, or sharing the implementation of sampleOn in a different way?

@neilpa
Copy link
Member

neilpa commented Nov 21, 2015

I was actually wondering if we should invert the startWithSignal order for the producers in lift. Dual synchronous producers also affect takeUntil and takeUntilReplacement but it's less clear for those what the "right" answer is. But since this is broken for sampleOn I would make an argument for the consistency of being left-biased.

The remaining binary lift implementations are combineLatestWith and zipWith which should behave the same regardless of order.

@neilpa
Copy link
Member

neilpa commented Nov 24, 2015

I was wrong above. Inverting the subscription order does affect combineLatestWith and breaks this test. I guess we'll need something like liftR and liftL, but hopefully someone has better names.

@NachoSoto
Copy link
Member Author

Inverting the subscription order does affect combineLatestWith and breaks this test

That's good to hear, actually!

I think liftLeft and liftRight sound good!

@NachoSoto
Copy link
Member Author

@neilpa I'm happy to implement that if that sounds good, unless you already have a working implementation of liftLeft?

@neilpa
Copy link
Member

neilpa commented Nov 25, 2015

Let me cleanup my change and I'll push it shortly

@NachoSoto
Copy link
Member Author

Reopened in #2571.

@NachoSoto NachoSoto closed this Nov 25, 2015
@neilpa neilpa deleted the sample-on-producer branch November 25, 2015 19:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants