Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TakeUntil not working as documented?

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();
like image 572
lbergnehr Avatar asked Oct 30 '22 09:10

lbergnehr


1 Answers

Preston Guillot is on point in the comments section:

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.

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.

like image 154
supertopi Avatar answered Nov 15 '22 04:11

supertopi