/// <summary>
        /// Advances the enumerator to the next element of the collection.
        /// </summary>
        /// <returns><see langword="true" /> if the enumerator was successfully advanced to the next element; <see langword="false" /> if the enumerator has passed the end of the collection.</returns>
        public bool MoveNext()
        {
            if (_messageQueue.Count == 0 && !_isInitialized)
            {
                return(false);
            }

            if (_isChanged)
            {
                _moveNextSyncRoot.WaitSignal();
            }

            var pair    = _messageQueue.Dequeue();
            var message = pair.Value;

            var serverTime = message.GetServerTime();

            if (serverTime != null)
            {
                _currentTime = serverTime.Value;
            }

            _currentMessage = (T)message;

            return(true);
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Advances the simulation to the specified moment in time.
 /// </summary>
 /// <param name="time">The moment in time to advance the simulation
 /// to, in nanoseconds.</param>
 public static void RunTo(ulong time)
 {
     while (Time < time)
     {
         var peek = events.Peek();
         if (peek == null || peek.Time > time)
         {
             Time = time;
         }
         else
         {
             var ev = events.Dequeue();
             Time = ev.Time;
             ev.Run();
         }
     }
 }
        public void DequeueTest()
        {
            var threads = new List <Thread>();

            threads.Add(new Thread(() => intQueue.Enqueue(1, 5)));
            threads.Add(new Thread(() => intQueue.Enqueue(2, 4)));
            threads.Add(new Thread(() => intQueue.Enqueue(3, 6)));

            foreach (var thread in threads)
            {
                thread.Start();
            }

            foreach (var thread in threads)
            {
                thread.Join();
            }

            Assert.AreEqual(3, intQueue.Dequeue());
            Assert.AreEqual(1, intQueue.Dequeue());
            Assert.AreEqual(2, intQueue.Dequeue());
        }