Cold versus hot Observables
There are subtle behaviors in a relationship between an Observable
and an Observer
depending on how the Observable
is implemented. A major characteristic to be aware of is cold versus hot Observables, which defines how Observables behave when there are multiple Observers. First, we will cover cold Observables.
Cold Observables
Cold Observables are much like a music CD that can be replayed to each listener, so each person can hear all the tracks at any time. In the same manner, cold Observables will replay the emissions to each Observer
, ensuring that all Observers get all the data. Most data-driven Observables are cold, and this includes the Observable.just()
and Observable.fromIterable()
factories.
In the following example, we have two Observers subscribed to one Observable
. The Observable
will first play all the emissions to the first Observer
and then call onComplete()
. Then, it will play all the emissions again to the second Observer
and call onComplete()
. They...