Created
October 30, 2017 10:03
-
-
Save SergejIsbrecht/c466e6811071c9ef6471c2fdd44a4619 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Test | |
public void observableLimit2() throws Exception { | |
long lowerBound = 0; | |
long higherBound = 1000; | |
long actualSum = (higherBound * (higherBound + 1)) / 2; | |
Single<Long> longSingle = Flowable.rangeLong(lowerBound, higherBound + 1) | |
.doOnNext(aLong -> System.out.println(Thread.currentThread().toString())) | |
.reduce(0L, (integer, aLong) -> { | |
return integer + aLong; | |
}) | |
.subscribeOn(Schedulers.io()); // do not do this for accumulating 1000 numbers. Switching between Thread / Tasks is expensive | |
longSingle.test().await().assertResult(actualSum); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment