I’m new to Reactive Extensions.
I have a room based MMOFPS game server with many rooms and only one listening socket. I create a cold observable which represents messages received from the network, and want to convert it to hot to be shared between multiple rooms so each room can filter and process their relevant messages. Is my approach correct?
Another problem, after converting the cold observable to hot I realized SubscribeOn lost its effect. For example:
var observable = Observable.Return(1).Publish();
observable
.Where(
x =>
{
Console.WriteLine("Filter on {0}", Thread.CurrentThread.ManagedThreadId);
return true;
})
.SubscribeOn(Scheduler.NewThread)
.ObserveOn(Scheduler.NewThread)
.Subscribe(x => Console.WriteLine("Received on {0}", Thread.CurrentThread.ManagedThreadId));
observable.Connect();
Console.WriteLine("End {0}", Thread.CurrentThread.ManagedThreadId);
Console.ReadLine();
Result:
Received on 12
End 10
Filter on 10
Without Publish:
Result:
End 10
Filter on 11
Received on 12
But when I use Publish.RefCount to auto connect, it works as expected.
Am I missing something? …
The order in which you apply operators is important. If you want to share the subscription side-effects of SubscribeOn, then you must apply it before Publish. For example:
For more information:
http://social.msdn.microsoft.com/Forums/pl-PL/rx/thread/29de2890-8303-404d-a6f8-f0fe0f716a86