什么是 Hot 和 Cold observables? [英] What are the Hot and Cold observables?

查看:23
本文介绍了什么是 Hot 和 Cold observables?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我观看视频,我知道一般原则 - 即使没有人订阅,也会发生热事件,按需"发生冷事件.此外,Publish() 将冷转换为热,Defer() 将热转换为冷.

I watched the video and I know the general principles - hot happens even when nobody is subscribed, cold happens "on demand". Also, Publish() converts cold to hot and Defer() converts hot to cold.

但是,我仍然觉得我缺少细节.以下是我想回答的一些问题:

But still, I feel I am missing the details. Here are some questions I'd like to have answered:

  • 您能为这些术语下一个全面的定义吗?
  • 在热的 observable 上调用 Publish 或在冷的时候调用 Defer 是否有意义?
  • 热/冷转换有哪些方面 - 例如,您是否会丢失消息?
  • IObservable 和 IEnumerable 的热定义和冷定义之间是否存在差异?
  • 在为冷或热编程时应考虑哪些一般原则?
  • 关于热/冷 observables 的任何其他提示?

推荐答案

我希望这会有所帮助.

能不能给个全面的这些术语的定义?

Can you give a comprehensive definition for these terms?

请参阅我的博客文章:http://leecampbell.blogspot.com/2010/08/rx-part-7-hot-and-cold-observables.html

打电话有意义吗?发布在一个热门的 observable 或 Defer 上感冒了?

Does it ever make sense to call Publish on a hot observable or Defer on a cold?

不,不是我能想到的.

Hot/Cold 有哪些方面转换 - 您是否会丢失消息,例如?

What are the aspects of Hot/Cold conversions - do you lose messages, for example?

当 Observable 处于热状态时,可能会丢失"消息,因为无论订阅者如何,事件"都会发生.

It is possible to "lose" messages when the Observable is Hot, as "events" happen regardless of subscribers.

热和热之间有区别吗?IObservable 的冷定义和IEnumerable?

Are there differences between hot and cold definitions for IObservable and IEnumerable?

我真的不明白这个问题.我希望这个类比有帮助.我会将 Hot Observable 与 Eagerly 评估的 IEnumerable 进行比较.即一个列表或一个数组都被急切地评估并被填充,即使没有人枚举它们.从文件或数据库中获取值的 yield 语句可以使用 Yield 关键字进行惰性求值.虽然惰性可能很好,但默认情况下,如果第二个枚举器运行它,它将被重新评估.将这些与 Observable 进行比较,Hot Observable 可能是一个事件(按钮单击)或温度馈送;无论订阅如何,这些事件都会发生,如果对同一个观察进行了多个订阅,这些事件也会被共享.Observable.Interval 是 Cold observable 的一个很好的例子.它只会在订阅后开始生成值.如果进行了多次订阅,则将重新评估序列,并且事件"将在不同的时间发生(取决于订阅之间的时间).

I dont really understand the question. I hope this analogy helps though. I would compare a Hot Observable to an Eagerly evaluated IEnumerable. ie a List or an Array are both Eagerly evaluated and have been populated even if no-one enuemerates over them. A yield statement that gets values from a file or a database could be lazily evaluated with the Yield keyword. While lazy can be good, it will by default, be reevaluated if a second enumerator runs over it. Comparing these to Observables, a Hot Observable might be an Event (Button click) or a feed of temperatures; these events will happen regardless of a subscription and would also be shared if multiple subscriptions were made to the same observale. Observable.Interval is a good example of a Cold observable. It will only start producing values when a subscription is made. If multiple subscriptions as made then the sequence will be re-evaluated and the "events" will occur at seperate times (depending on the time between subscriptions).

在为冷或热编程时应该考虑哪些一般原则?

What are the general principles you should take into account when programming for cold or hot?

请参阅第一点中的链接.我还建议您研究将 Publsh 与 RefCount 结合使用.这使您能够拥有 Cold Observables 的 Lazy 评估语义,但共享 Hot Observables 获得的事件.

Refer to the link in point one. I would also recommend you look into Publsh being used in conjunction with RefCount. This allows you to have the ability to have Lazy evaluation semantics of Cold Observables but the sharing of events that Hot Observables get.

关于热/冷的任何其他提示可观察?

Any other tips on hot/cold observables?

弄脏你的手,和他们一起玩.一旦你阅读了超过 30 分钟的内容,那么花时间与他们一起编码对你来说比阅读更多有效率:)

Get your hands dirty and have a play with them. Once you have read about them for more than 30minutes, then time spent coding with them is far more productive to you than reading any more :)

这篇关于什么是 Hot 和 Cold observables?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆