system.reactive - 什么是热观测值和冷观测值?

标签 system.reactive

I watched the video我知道一般原则 - 即使没有人订阅,热也会发生,冷会“按需”发生。 另外,Publish() 将冷数据转换为热数据,Defer() 将热数据转换为冷数据。

但是,我仍然觉得我错过了细节。以下是我想回答的一些问题:

  • 您能为这些术语给出一个全面的定义吗?
  • 对热 observable 调用 Publish 或对冷 observable 调用 Defer 是否有意义?
  • 热/冷转换有哪些方面 - 例如,您是否会丢失消息?
  • IObservable 和 IEnumerable 的热定义和冷定义之间有区别吗?
  • 针对冷或热编程时应考虑哪些一般原则?
  • 关于热/冷可观察量还有其他提示吗?

最佳答案

来自:Anton Moiseev 的书 “Angular Development with Typescript, Second Edition.” :

Hot and cold observables

There are two types of observables: hot and cold. The main difference is that a cold observable creates a data producer for each subscriber, whereas a hot observable creates a data producer first, and each subscriber gets the data from one producer, starting from the moment of subscription.

Let’s compare watching a movie on Netflix to going into a movie theater. Think of yourself as an observer. Anyone who decides to watch Mission: Impossible on Netflix will get the entire movie, regardless of when they hit the play button. Netflix creates a new producer to stream a movie just for you. This is a cold observable.

If you go to a movie theater and the showtime is 4 p.m., the producer is created at 4 p.m., and the streaming begins. If some people (subscribers) are late to the show, they miss the beginning of the movie and can only watch it starting from the moment of arrival. This is a hot observable.

A cold observable starts producing data when some code invokes a subscribe() function on it. For example, your app may declare an observable providing a URL on the server to get certain products. The request will be made only when you subscribe to it. If another script makes the same request to the server, it’ll get the same set of data.

A hot observable produces data even if no subscribers are interested in the data. For example, an accelerometer in your smartphone produces data about the position of your device, even if no app subscribes to this data. A server can produce the latest stock prices even if no user is interested in this stock.

关于system.reactive - 什么是热观测值和冷观测值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2521277/

相关文章:

c# - 如何将 Observable 值路由到不同的订阅者?

linq - System.IObservable<字符串> 到 System.IObservable<System.Collections.Generic.List<字符串>>

f# - 在可移植类库上使用 F# 中的 Rx 现在还有一些问题吗?

c# - 使用 Reactive Extensions (RX),是否可以添加 "Pause"命令?

c# - 如何在wpf中延迟调用文本框的textchanged事件

c# - Reactive Extensions - 将项目从一个集合抽取到另一个集合

.net - 响应式(Reactive)扩展 IObservable 在订阅者订阅时发出通知

wpf - Rx-WPF 和 Rx-Xaml 包之间有什么区别吗?

c# - Observable 中的通知并行性

c# - 在 Rx 和 LINQ(或者一般来说,流和列表)之间共享查询