Why is my RX chain blocking?

c#, system.reactive

Solution

Ensuring events are delivered to a subscriber serially is a core part of the Rx grammar and fundamental to it's correct operation. It is enforced in most of the Rx operators and you should not violate this.

The mechanics of ObserveOn and SubscribeOn are addressed quite fully here.

The purpose of ObserveOn is to either avoid blocking the thread of the observable that is dispatching events and/or to control the thread on which subscribers receive events (in your case using the task pool to deliver them).

What it does not do is allow a subscriber to receive events concurrently - which as I said, would be in violation of the rules of Rx.

You might find this question on a similar topic worth reading too.

Problem

So I have the following RX change, but it seems to block on the select as if to preserve order. My understanding is that it should just keep delegating to the task pool? ``` var observable = Observable.Interval(TimeSpan.FromMilliseconds(10)); observable.ObserveOn(Scheduler.TaskPool) .Select( i => { Console.WriteLine("Here" + System.Threading.Thread.CurrentThread.ManagedThreadId); System.Threading.Thread.Sleep(5000); return i; }) .ObserveOn(Scheduler.TaskPool) .SubscribeOn(Scheduler.TaskPool) .Subscribe(i => { Console.WriteLine(i); }); ```

Original source

Related problems