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

scan should pass upstream a request of Long.MAX_VALUE #3727

Merged
merged 1 commit into from
Feb 24, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/main/java/rx/internal/operators/OperatorScan.java
Original file line number Diff line number Diff line change
Expand Up @@ -268,8 +268,12 @@ public void setProducer(Producer p) {
if (producer != null) {
throw new IllegalStateException("Can't set more than one Producer!");
}
mr = missedRequested;
// request one less because of the initial value, this happens once
mr = missedRequested - 1;
// and is performed only if the request is not at MAX_VALUE already
if (mr != Long.MAX_VALUE) {
mr -= 1;
}
missedRequested = 0L;
producer = p;
}
Expand Down
18 changes: 18 additions & 0 deletions src/test/java/rx/internal/operators/OperatorScanTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -451,4 +451,22 @@ public void onNext(Integer t) {
}
});
}

@Test
public void scanShouldPassUpstreamARequestForMaxValue() {
final List<Long> requests = new ArrayList<Long>();
Observable.just(1,2,3).doOnRequest(new Action1<Long>() {
@Override
public void call(Long n) {
requests.add(n);
}
})
.scan(new Func2<Integer,Integer, Integer>() {
@Override
public Integer call(Integer t1, Integer t2) {
return 0;
}}).count().subscribe();

assertEquals(Arrays.asList(Long.MAX_VALUE), requests);
}
}