I watched the new rx java 2 and I'm not quite sure that I understand the idea of backpressure ...
I know that we have an Observable that does not have backpressure support and Flowable that has it.
So, for example, let's say I have a Flowable with interval :
Flowable.interval(1, TimeUnit.MILLISECONDS, Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .subscribe(new Consumer<Long>() { @Override public void accept(Long aLong) throws Exception {
This will crash after 128 values, and it is pretty obvious that I consume more slowly than getting items.
But then we have the same thing with Observable
Observable.interval(1, TimeUnit.MILLISECONDS, Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .subscribe(new Consumer<Long>() { @Override public void accept(Long aLong) throws Exception {
This will not work at all, even if I take care of its consumption, it still works. To make Flowable work, let's say I put the onBackpressureDrop , the crash disappeared, but not all values are also emitted.
So, the basic question I cannot find in my head, why should I care about backpressure , when I can use plain Observable , still get all the values without buffer control? Or maybe, on the other hand, what are the benefits of backpressure in favor of managing and processing consumption?
java android rx-java
user2141889 Oct 29 '16 at 20:19 2016-10-29 20:19
source share