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

Fix 'request(0)' issue in Scan #1957

Merged
merged 1 commit into from
Dec 13, 2014
Merged

Conversation

zsxwing
Copy link
Member

@zsxwing zsxwing commented Dec 12, 2014

#1904 didn't all cases.

@@ -147,19 +147,17 @@ public void request(long n) {
if (once.compareAndSet(false, true)) {
if (initialValue == NO_INITIAL_VALUE || n == Long.MAX_VALUE) {
producer.request(n);
} else if (n == 1) {
excessive.set(true);
Copy link
Member

Choose a reason for hiding this comment

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

What does excessive mean? I'm re-reading this code and the intent of that variable doesn't jump out at me.

Copy link
Member Author

Choose a reason for hiding this comment

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

It means we request more than what we should.

If a user requests 1 from scan in onStart, scan need to request 1 to the upstream. However, when scan receives an onNext, it will emit 2 onNext to the downstream: the initial value and accumulator.call(this.value, initialvalue). So the downstream only requests 1, but scan emits 2 values. I use excessive to indicate we are in an excessive state.

So the next time when the downstream requests, I will try to request n-1.

Copy link
Member Author

Choose a reason for hiding this comment

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

If a user requests X (X > 1) from scan in onStart, scan can simply request (X-1). In such case, excessive will be false.

Copy link
Member

Choose a reason for hiding this comment

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

Got it, thanks for the explanation.

@benjchristensen
Copy link
Member

The logic seems correct to me on a re-read of this code.

benjchristensen added a commit that referenced this pull request Dec 13, 2014
Fix 'request(0)' issue in Scan
@benjchristensen benjchristensen merged commit 73715bf into ReactiveX:1.x Dec 13, 2014
@zsxwing zsxwing deleted the fix-scan branch December 14, 2014 05:44
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