Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is RxJava 2 Flowable hot or cold?

I used to think that RxJava 2's Flowable was designed to be "hot" and Observable "cold". But I think that's wrong now - That Observable and Flowable are both cold but can be made hot e.g. by making either Connectable. Is this correct?

like image 219
Julian A. Avatar asked Nov 30 '25 07:11

Julian A.


1 Answers

I think we should define element by element:

Cold vs Hot

In the case of Observable cold and hot, we could define that a cold is when an Observable emits the same defined events to whom it subscribes, for example Observable.just (1, 2, 3, 4, 5) while hot could be events that could not be exactly the same all the time, for example the result of a query to the database or a request to server through retrofit.

Then we could define a Flowable.just (1, 2, 3, 4, 5) or an Observable.just (1, 2, 3, 4, 5) as cold, in this case there are just few elements and not being a sequence that will be continuously sending items, it would be worth keeping it as Observable.

Think in cold Observable as a music CD, you will always listen to the same songs and in the same order, no matter how many times you use it, while a hot Observable is like a radio station, you will regularly receive different information, maybe you subscribed late and finished the radio show you wanted to listen to or it's just different.

Observable vs Flowable

Now the main difference between an Observable and a Flowable is that Flowable supports back pressure, prevents loss of information in case it cannot consume the events as fast as it is receiving them.

https://github.com/ReactiveX/RxJava/wiki/Backpressure-(2.0)

ConnectableObservable

In the ConnectableObservable case, the Publisher begins to emit information to the subscribers after executing ConnectableObservable::connect, regardless of whether the observable sender is cold or hot.

Then

The important thing is to identify if it is necessary to use an Observable or a Flowable and according to how they emit their values ​​we can call it cold or hot.

The next book gave me a big push: https://www.amazon.com/Learning-RxJava-Thomas-Nield/dp/1787120422

like image 90
Julio Lemus Avatar answered Dec 03 '25 04:12

Julio Lemus



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!