TakeUntil not working as documented?

爷,独闯天下 提交于 2020-01-13 05:06:09

问题


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

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();

回答1:


Preston Guillot is on point in the comments section.

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.

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



来源:https://stackoverflow.com/questions/35417909/takeuntil-not-working-as-documented

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!