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 :
- We can create a Flowable using the just() method.
Flowable from Observable :
- Observable we can be easily transform to Flowable using the toFlowable() method.
Flowable from FlowableOnSubscribe :
- RxJava 2 introduced a functional interface FlowableOnSubscribe, which represents a Flowable that starts emitting events after the consumer subscribes to it.
Backpressure Strategy:
Dropping
- Discards the unrequested items if it exceeds the buffer size.
Latest :
- Preserve the latest item
- It is type of observables which emits 0 or n items and terminates with an success or an error event.
- Supports backpressure.
Buffring :
- Buffers all the items from the producer, watch for OOMs.
- Error throws a MissingBackpressureException in case of over emission
Missing:
- No strategy, it would throw a MissingBackpressureException sooner or later somewhere on the downstream
Comments
Post a Comment