是什么在所有这些反应观测扩展的实际差别? [英] What is the practical difference among all of these Reactive Observable extensions?

查看:123
本文介绍了是什么在所有这些反应观测扩展的实际差别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

给定一个BehaviorSubject,什么叫所有这些不同的功能上的实际差别?

Given a BehaviorSubject, what is the practical difference between calling all of these different functions on it?

  • 在第一个()
  • 在最后()
  • LatestValue()
  • MostRecentValue()
  • NextValue()
  • 在单()
  • 拍摄(1)

假设我的理解是正确的,他们都应该做同样的事情,考虑到BehaviorSubject。

Assuming I understand it right, they should all do about the same thing, given the BehaviorSubject.

如果是这样,那么它的呼叫是最合适的(我指的是:最能传达我的意图)?首先还是单身吧?

If so, then which call is the most appropriate (by which I mean: which best communicates my intent)? First or Single perhaps?

如果不是,那么有什么实际的区别在哪里?

If not, then what are the practical differences?

推荐答案

首先,最后和单是阻塞;建议使用取(1)来代替,这样你就得到一个的IObservable回来。当链接查询操作建议,以避免第一,最后和单因为你退出单子......就是说你已经封锁副作用的安全性。请参阅<一href="http://blogs.msdn.com/jeffva/archive/2009/12/09/first-last-contains-etc-can-be-extremely-dangerous-yet-extremely-useful.aspx">http://blogs.msdn.com/jeffva/archive/2009/12/09/first-last-contains-etc-can-be-extremely-dangerous-yet-extremely-useful.aspx所有关于这一点。

First, Last, and Single are blocking; it is recommended to use Take(1) instead, so you get an IObservable back. When chaining query operators it is recommended to avoid First, Last and Single because you exit the safety of the monad ... that is to say you have blocking side effects. See http://blogs.msdn.com/jeffva/archive/2009/12/09/first-last-contains-etc-can-be-extremely-dangerous-yet-extremely-useful.aspx for more about that.

MostRecentValue和LatestValue已经从接收的最新版本中删除,因为它们都是阻塞一样,所以只剩下阻止运营商首先,去年和单(以及xxxOrDefault变种),根据最新的发行说明。

MostRecentValue and LatestValue have been removed from the latest version of Rx because they are blocking as well, so the only blocking operators left are First, Last, and Single (and the xxxOrDefault variants), according to the latest release notes.

MostRecent将返回采样的最后一个值,您拨打尽量多(这需要一个初值,以保证它永远不会等待),即不消费,而最新的会等到一个数值到达然后回吧消费 - 也就是说,如果你调用最新的一次也不会返回相同的值作为最后一个电话时,它会等到下一个值到达时,如果有的话

MostRecent will return the last value sampled, as often as you call it (and it takes an initialValue to guarantee it will never wait), i.e. "without consumption", whereas Latest will wait until a value arrives then return it "with consumption" - that is, if you call Latest again it will not return the same value as the last call, it will wait until the next value arrives, if ever.

这篇关于是什么在所有这些反应观测扩展的实际差别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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