O'Reilly logo

Reactive Android Programming by Tadas Subonis

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Buffering

Buffering is usually a poor way to handle different paces of items being emitted and consumed as it often just delays the problem.

However, it can work just fine if there is just a temporal slowdown in one of the consumers. In this case, the items emitted will be stored until later processing and when the slowdown is over, the consumers will catch up. If the consumers cannot catch up, at some point the buffer will run out and we can see a very similar behavior to the original Observable with memory running out.

Enabling buffers is, again, pretty straightforward by calling the following:

observable.toFlowable(BackpressureStrategy.BUFFER)

Alternatively, you can call this:

observable.toFlowable(BackpressureStrategy.MISSING) .onBackpressureBuffer() ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required