Ejemplo n.º 1
0
        public TimerSystem(ITimerSystemImplementation <T> implementation, Action <Exception> handleException)
        {
            this.implementation = implementation;
            this.implementation.Start(handleException);
            BehaviorSink <T> timeSink = new BehaviorSink <T>(this.implementation.Now);

            this.Time = timeSink;
            Transaction.OnStart(
                () =>
            {
                T t = this.implementation.Now;
                this.implementation.RunTimersTo(t);
                while (true)
                {
                    Event ev = null;
                    // Pop all events earlier than t.
                    lock (this.eventQueue)
                    {
                        if (this.eventQueue.Count > 0)
                        {
                            Event tempEvent = this.eventQueue.Peek();
                            if (tempEvent != null && tempEvent.Time.CompareTo(t) <= 0)
                            {
                                ev = this.eventQueue.Dequeue();
                            }
                        }
                    }

                    if (ev != null)
                    {
                        timeSink.Send(ev.Time);
                        ev.Alarm.Send(ev.Time);
                    }
                    else
                    {
                        break;
                    }
                }

                timeSink.Send(t);
            });
        }
Ejemplo n.º 2
0
 public Implementation(Action <Exception> handleException)
 {
     this.implementation = new SystemClockTimerSystem.Implementation(handleException);
     this.startTime      = this.implementation.Now;
 }