gpt4 book ai didi

rxjs - Rx Observable 有多少个 "temperatures"?

转载 作者:行者123 更新时间:2023-12-01 04:36:58 25 4
gpt4 key购买 nike

在 Rx.Net 的所有文献中,都提到了通常称为 的内容。温度 一个可观察的。

冷观测 (就像由 Observable.Interval() 和类似工厂方法创建的那些),每次创建新订阅时都会产生副作用。

在频谱的另一边有 热观测 (如 Subject<T> )将在新订阅到来时加入。

还有温暖的观测 ,就像 RefCount() 返回的那些每次创建一个订阅时都会执行初始化,但前提是没有其他事件订阅。解释了这些温暖的可观察对象的行为 here戴夫·塞克斯顿:

Alternatively, you can call Publish then RefCount to get an IObservable that is shared among multiple consecutive observers. Note that this isn't truly a hot observable - it's more like a warm observable. RefCount makes a single subscription to the underlying observable while there's at least one observer of your query. When your query has no more observers, changing the reference count to 0, the underlying subscription is disposed. If another observer subscribes to your query later, moving the reference count from 0 to 1 again, then RefCount makes a new subscription to the underlying observable, causing subscription side-effects to occur again.



还有其他温度需要注意吗?是否可以通过编程方式获得 Observable 的温度?

最佳答案

首先简单的问题:

Is it possible to obtain programmatically the temperature of an Observable?



不。你能做的最好的事情就是订阅,看看会发生什么。

observable 'contract' 指定当您订阅一个 observable 时,您会收到零个或多个 OnNext 消息,可选地后跟一个 OnCompleted 或一个 OnError 消息。契约(Contract)没有具体说明如何对待多个或更早/更晚的订阅者,这是可观察到的“温度”最关心的问题。

Are there any other temperatures that one should be aware of?



我什至不会像您指定的那样以具体或离散的术语来考虑它。

我从订阅效应的角度来考虑它:最冷的 observables 的所有影响都发生在订阅上(如 Observable.Return(42))。 HitTest 门的 observables 对 subscribe ( new Subject<int>() ) 没有影响。在这两个极点之间是一个连续体。
Observable.Interval(TimeSpan.FromMilliseconds(100))例如将每 100 毫秒发出一个新数字。那个例子,不像 Observable.Return(42) , 可能主要通过 .Publish().RefCount() 进行“预热” : 第一个订阅者开始数字,但第二个订阅者只会看到最新的数字,而不是从 0 开始。但是,如果不是 .Publish()你做了 .Replay(2).RefCount() ,那么您就会有一些订阅效果。做 PublishReplay可观察对象具有相同的“温度”?

TL;DR:不要太关注分类。了解两者之间的区别,并知道一些可观测物具有较冷的特性,而另一些具有较暖的特性。

关于rxjs - Rx Observable 有多少个 "temperatures"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52649015/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com