Hot and Cold Observables
IMHO, I would suggest to more think of this as property of sequences and not separate types because they are represented by the same abstraction that fits them perfectly, Observable
sequence.
This is a definition from ReactiveX.io
When does an Observable begin emitting its sequence of items? It depends on the Observable. A “hot” Observable may begin emitting items as soon as it is created, and so any observer who later subscribes to that Observable may start observing the sequence somewhere in the middle. A “cold” Observable, on the other hand, waits until an observer subscribes to it before it begins to emit items, and so such an observer is guaranteed to see the whole sequence from the beginning.
Hot Observables | Cold observables |
---|---|
... are sequences | ... are sequences |
Use resources ("produce heat") no matter if there is any observer subscribed. | Don't use resources (don't produce heat) until observer subscribes. |
Variables / properties / constants, tap coordinates, mouse coordinates, UI control values, current time | Async operations, HTTP Connections, TCP connections, streams |
Usually contains ~ N elements | Usually contains ~ 1 element |
Sequence elements are produced no matter if there is any observer subscribed. | Sequence elements are produced only if there is a subscribed observer. |
Sequence computation resources are usually shared between all of the subscribed observers. | Sequence computation resources are usually allocated per subscribed observer. |
Usually stateful | Usually stateless |