Skip to content

Commit a57bccc

Browse files
committed
Merge pull request #3727 from davidmoten/scan-request-bug
scan should pass upstream a request of Long.MAX_VALUE
2 parents 3e6affd + 457533c commit a57bccc

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

src/main/java/rx/internal/operators/OperatorScan.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,8 +268,12 @@ public void setProducer(Producer p) {
268268
if (producer != null) {
269269
throw new IllegalStateException("Can't set more than one Producer!");
270270
}
271+
mr = missedRequested;
271272
// request one less because of the initial value, this happens once
272-
mr = missedRequested - 1;
273+
// and is performed only if the request is not at MAX_VALUE already
274+
if (mr != Long.MAX_VALUE) {
275+
mr -= 1;
276+
}
273277
missedRequested = 0L;
274278
producer = p;
275279
}

src/test/java/rx/internal/operators/OperatorScanTest.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -451,4 +451,22 @@ public void onNext(Integer t) {
451451
}
452452
});
453453
}
454+
455+
@Test
456+
public void scanShouldPassUpstreamARequestForMaxValue() {
457+
final List<Long> requests = new ArrayList<Long>();
458+
Observable.just(1,2,3).doOnRequest(new Action1<Long>() {
459+
@Override
460+
public void call(Long n) {
461+
requests.add(n);
462+
}
463+
})
464+
.scan(new Func2<Integer,Integer, Integer>() {
465+
@Override
466+
public Integer call(Integer t1, Integer t2) {
467+
return 0;
468+
}}).count().subscribe();
469+
470+
assertEquals(Arrays.asList(Long.MAX_VALUE), requests);
471+
}
454472
}

0 commit comments

Comments
 (0)