Skip to content

Instantly share code, notes, and snippets.

@SergejIsbrecht
Created October 30, 2017 10:03
Show Gist options
  • Save SergejIsbrecht/c466e6811071c9ef6471c2fdd44a4619 to your computer and use it in GitHub Desktop.
Save SergejIsbrecht/c466e6811071c9ef6471c2fdd44a4619 to your computer and use it in GitHub Desktop.
@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