Why doesn't my RxJava Flowable respect backpressure when using observeOn? Why doesn't my RxJava Flowable respect backpressure when using observeOn? multithreading multithreading

Why doesn't my RxJava Flowable respect backpressure when using observeOn?


How can I have my Flowable respect backpressure across a Scheduler

Actually, applying onBackpressureBuffer makes the source above it disconnect from any backpressure applied by downstream as it is an unbounded-in operator. You don't need it because Flowable.fromIterable (and by the way, RxJava has a range operator) supports and honors backpressure.

Why does it seem to only disrespect backpressure when I sprinkle in calls to observeOn?

In the first example, there is a natural backpressure happening called call-stack blocking. RxJava is synchronous by default and most operators don't introduce asynchrony, just like none do in the first example.

observeOn introduces an asynchronous boundary thus in theory, stages can run in parallel with each other. It has a default 128 element prefetch buffer which can be adjusted via one of its overloads. In your case, however, buffer(10) will actually amplify the prefetch amount to 1280 which may still lead to the complete consumption of your 1000 element long source in one go.