TakeUntil 不能按文档工作? [英] TakeUntil not working as documented?

查看:26
本文介绍了TakeUntil 不能按文档工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

来自 TakeUntil 操作符的文档(强调我的):

From the docs for the TakeUntil operator (emphasis mine):

TakeUntil 订阅并开始镜像源 Observable.它还监视您提供的第二个 Observable.如果第二个 Observable 发出项目或发送终止通知,TakeUntil 返回的 Observable 将停止镜像源 Observable 并终止.

The TakeUntil subscribes and begins mirroring the source Observable. It also monitors a second Observable that you provide. If this second Observable emits an item or sends a termination notification, the Observable returned by TakeUntil stops mirroring the source Observable and terminates.

如果这是真的,那么为什么会阻止?:

If this is true, then why does this block?:

Observable.Never<Unit>()
    .TakeUntil(Observable.Empty<Unit>())
    .Wait();

推荐答案

Preston Guillot 在评论部分指出:

Preston Guillot is on point in the comments section:

(旧)MSDN 文档 与主 Rx 站点的不同,仅声明 TakeUntil 从源可观察序列返回值,直到另一个可观察序列产生值."不考虑终止的 observables.

The (old) MSDN Documentation is different than the main Rx site's, and only states that TakeUntil "Returns the values from the source observable sequence until the other observable sequence produces a value." without considering terminated observables.

让我们看看 查看Observable.TakeUntil 的源代码,特别是表示终结者"的class O可观察.我们可以看到 parent.OnCompleted 通知是在 O.OnNextO.OnError 上发送的.

Let's take a look at the source code for Observable.TakeUntil, specifically class O which represents the "terminator" Observable. We can see that parent.OnCompleted notification is sent on O.OnNext and O.OnError.

因此,您的代码阻塞的原因是 Observable.Empty(充当终止符")仅发出 OnCompleted 通知.

So the reason why your code is blocking, is that Observable.Empty (which acts as the "terminator") emits only an OnCompleted notification.

这篇关于TakeUntil 不能按文档工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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