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

Sample operator: last item before termination is dropped after sampling #3657

Closed
kboyarshinov opened this issue Jan 31, 2016 · 12 comments
Closed

Comments

@kboyarshinov
Copy link

Hi. Recently I found that sample operator drops last value before onCompleted event. This is behaviour is valid according to these discussions #566 and #571 and this test. It originated in Rx.NET and still exists in RxJava to be consistent across all implementations as far as I understood.

But, marble diagram in documentation shows otherwise: item 5 is emitted before termination and sampled by sampler.
sample_marble

This behaviour is odd and unexpectable. I stumbled across it trying to resolve backpressure issue with observables where last emitted item is the most important.

So, my question is whether it can be changed? I prepared a commit with fixes and corresponding tests.
Or at least marble diagram should be changed to showcase this behaviour and it would be good to have a note about it in documentation.

Thank you.

@akarnokd
Copy link
Member

What about when the source completes and the sampler doesn't?

@kboyarshinov
Copy link
Author

@akarnokd it would emit the last item from completed source and nothing after that, no?

@akarnokd
Copy link
Member

Right, the diff tricked me. I expected 3 calls to emit, 1 in sampler's onNext, 1 in sampler's onCompleted and 1 in parent's onCompleted.

Besides, I can see that operator still has some issues with unsubscription and backpressure management.

@kboyarshinov
Copy link
Author

Yep, 2 calls is enough: 1 in sampler's onNext and 1 in parent's onCompleted.

@akarnokd
Copy link
Member

So if the sampler completes, then the value should be dropped just like now?

@kboyarshinov
Copy link
Author

It is ok in my usecase. If sampler completes before source completes it means no values are expected before completion. But if source completes before sampler does it should emit last value.

However, it worth discussing.

@akarnokd
Copy link
Member

See #3658 that contains other fixes.

@kboyarshinov
Copy link
Author

Great! Also OperatorSampleWithTime will require fixes too.

@akarnokd
Copy link
Member

Would you like to submit a PR?

@kboyarshinov
Copy link
Author

@akarnokd I would like to. Will submit soon.

@kboyarshinov
Copy link
Author

Done #3757

@akarnokd
Copy link
Member

#3757 merged.

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

No branches or pull requests

2 participants