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()

If there is a need to specify a particular value for the buffer, one can use .buffer():

observable.toFlowable(BackpressureStrategy.MISSING)
.buffer(10)
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.133.157.142