public AmbDecisionObserver(AmbOuterObserver parent, AmbState me, IDisposable otherSubscription, Amb self) { this.parent = parent; this.me = me; this.otherSubscription = otherSubscription; this.self = self; }
public IDisposable Run() { var ls = new SingleAssignmentDisposable(); var rs = new SingleAssignmentDisposable(); var d = StableCompositeDisposable.Create(ls, rs); var gate = new object(); var lo = new AmbObserver(); lo._disposable = d; lo._target = new DecisionObserver(this, gate, AmbState.Left, ls, rs, lo); var ro = new AmbObserver(); ro._disposable = d; ro._target = new DecisionObserver(this, gate, AmbState.Right, rs, ls, ro); _choice = AmbState.Neither; ls.Disposable = _parent._left.SubscribeSafe(lo); rs.Disposable = _parent._right.SubscribeSafe(ro); return(d); }
/// <summary> /// The core code in class Amb. How it can propagate the observable sequence that reacts first? /// Because of the lazy evaluation of C#, it will only execute when the code runs into SubscribeSafe. /// SubscribeSafe takes an observer as a parameter which will initialize only when called. /// In the procedure of parameter initializing, other observable resoures will dispose, only left the reacted one. /// </summary> /// <returns></returns> public IDisposable Run() { var ls = new SingleAssignmentDisposable(); var rs = new SingleAssignmentDisposable(); var d = new CompositeDisposable(ls, rs); // Initializes a new instance of the System.Object class. var gate = new object(); // Initialize all observers. var lo = new AmbObserver(); lo._disposable = d; // Initialize a instance of DecisionObserver class. lo._target = new DecisionObserver(this, gate, AmbState.Left, ls, rs, lo); var ro = new AmbObserver(); ro._disposable = d; ro._target = new DecisionObserver(this, gate, AmbState.Right, rs, ls, ro); //Initialize the Enum state to Neither. _choice = AmbState.Neither; // Observers subscribe the resource. ls.Disposable = _parent._left.SubscribeSafe(lo); rs.Disposable = _parent._right.SubscribeSafe(ro); return(d); }
public DecisionObserver(_ parent, object gate, AmbState me, IDisposable subscription, IDisposable otherSubscription, AmbObserver observer) { _parent = parent; _gate = gate; _me = me; _subscription = subscription; _otherSubscription = otherSubscription; _observer = observer; }