Flowable and back pressure


Backpressure : 

The process of handling a fast item producer means it allows to control how fast a source emits items



RxJava 2 introduced Flowable to represent backpressure-aware sources using a dedicated class

Flowable : 


It is type of observables which emits 0 or n items and terminates with an success or an error event.
Supports backpressure.

Creating Flowables :


Simple Flowable : 


  1. We can create a Flowable using the just() method.


Flowable from Observable : 



  1.  Observable we can be easily transform to Flowable using the toFlowable() method.

Flowable from FlowableOnSubscribe : 



  1. RxJava 2 introduced a functional interface FlowableOnSubscribe, which represents a Flowable that starts emitting events after the consumer subscribes to it.


Backpressure Strategy:

Dropping


  1. Discards the unrequested items if it exceeds the buffer size.

    Latest : 

    1. Preserve the latest item
    2. It is type of observables which emits 0 or n items and terminates with an success or an error event.
    3. Supports backpressure.

    Buffring : 


    1. Buffers all the items from the producer, watch for OOMs.
    2. Error throws a MissingBackpressureException in case of over emission

    Missing: 


    1. No strategy, it would throw a MissingBackpressureException sooner or later somewhere on the downstream

    Reactive Pull

    In reactive pull, subscriber requests required number of items from observable by calling request()

    Comments

    Popular posts from this blog

    Android Interview question

    A complete guide to learn Android Development