protected void WhenLoop(IEnumerable <WhenStep> steps) { foreach (var step in steps) { _timeProvider.AddToUtcTime(TimeSpan.FromMilliseconds(10)); if (step.Action != null) { step.Action(); } foreach (var message in step) { if (message != null) { _queue.Publish(message); } } _queue.ProcessTimer(); if (_otherQueues != null) { foreach (var other in _otherQueues) { other.ProcessTimer(); } } var count = 1; var total = 0; while (count > 0) { count = 0; count += _queue.ProcessNonTimer(); if (_otherQueues != null) { foreach (var other in _otherQueues) { count += other.ProcessNonTimer(); } } total += count; if (total > 2000) { throw new Exception("Infinite loop?"); } } // process final timer messages } _queue.Process(); if (_otherQueues != null) { foreach (var other in _otherQueues) { other.Process(); } } }
protected void WhenLoop() { _queue.Process(); foreach (var message in (from steps in PreWhen().Concat(When()) from m in steps select m)) { if (message != null) { _queue.Publish(message); } _queue.Process(); } // process final timer messages _queue.Process(); }