Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between Cold or Hot http requests?

Could somebody explain me two things:

  • Difference between Cold or Hot http requests?
  • Are http requests in Angular 2 Cold or Hot?
like image 953
Max K Avatar asked Mar 15 '17 16:03

Max K


People also ask

What is the difference between Hot & Cold observable?

An Observable is cold when data is produced inside the Observable and the Observable is hot when the data is produced outside the Observable.

Which of the following is an example of a hot 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.

What is hot observable?

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.

Is subject hot or cold?

The Subject itself is hot/shared.


1 Answers

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.

like image 145
snorkpete Avatar answered Nov 29 '22 20:11

snorkpete