Could somebody explain me two things:
An Observable is cold when data is produced inside the Observable and the Observable is hot when the data is produced outside the Observable.
A typical example of a hot observable are mousemove events. The mouse moves happen regardless if someone is listening or not. When we start listening for them, we only get future events. Cold Observables on the other hand are the lazy ones.
Hot observables are ones that are pushing event when you are not subscribed to the observable. Like mouse moves, or Timer ticks or anything like that. Cold observables are ones that start pushing only when you subscribe, and they start over if you subscribe again.
The Subject itself is hot/shared.
In Angular, http requests made from the Http service are cold.
Cold, in this context, means that the http request is not made until someone subscribes to the observable returned from Http.get, Http.post etc. Also, each subscription to an http observable will cause a different http request to be fired. This is because, as a cold observable, the http observable is responsible for creating its producer (i.e. the Ajax request) on subscription, and each subscription will create a separate producer of values (i.e. separate Ajax requests).
Thoughtram has a detailed article on hot vs cold observables.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With