in my example below where I have 2 subjects and the _primarySubject is always called before the _secondarySubject is the subscriber guaranteed to receive the primary callback before the secondary callback? Test simple test seems to say yes or is this by fluke?
And if this is by fluke how can i change the code to guarantee order as I describe here.
Thanks a lot.
public class EventGenerator
{
ISubject<string> _primarySubject = new Subject<string>();
ISubject<int> _secondarySubject = new Subject<int>();
private int i;
public void SendEvent(string message)
{
_primarySubject.OnNext(message);
_secondarySubject.OnNext(i++);
}
public IObservable<string> GetPrimaryStream()
{
return _primarySubject;
}
public IObservable<int> GetSecondaryStream()
{
return _secondarySubject;
}
}
public class EventSubscriber
{
private static IScheduler StaticFakeGUIThread = new EventLoopScheduler(x => new Thread(x) { Name = "GUIThread" });
private readonly int _id;
public EventSubscriber(int id, EventGenerator eventGenerator)
{
_id = id;
eventGenerator.GetPrimaryStream().ObserveOn(StaticFakeGUIThread).Subscribe(OnPrimaryEvent);
eventGenerator.GetSecondaryStream().ObserveOn(StaticFakeGUIThread).Subscribe(OnSecondaryEvent);
}
private void OnPrimaryEvent(String eventMsg)
{
string msg = eventMsg;
}
private void OnSecondaryEvent(int i)
{
int msg = i;
}
}
[TestFixture]
public class EventGeneratorTest
{
[Test]
public void Test()
{
EventGenerator eg = new EventGenerator();
EventSubscriber s1 = new EventSubscriber(1,eg);
EventSubscriber s2 = new EventSubscriber(2, eg);
eg.SendEvent("A");
eg.SendEvent("B");
}
}