Difference between Cold or Hot http requests?

陌路散爱 提交于 2019-12-19 09:10:49

问题


Could somebody explain me two things:

  • Difference between Cold or Hot http requests?
  • Are http requests in Angular 2 Cold or Hot?

回答1:


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.




回答2:


Its cold since any request only starts producing value first when you subscribe to it. Without running

http.get().subscribe((response) => ...)

No request will be send to the server. http.get() alone is just an object.



来源:https://stackoverflow.com/questions/42815886/difference-between-cold-or-hot-http-requests

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!