/// <summary> /// Asynchronously processes an event queue by dispatching the events /// </summary> /// <param name="preTransaction">True, if pre-transaction handlers required</param> /// <param name="queue">The event queue to process</param> private async Task ProcessEventQueue(IEventQueue queue, bool preTransaction = false) { var queueTasks = new List <Task>(); while (false == queue.IsEmpty()) { var nextItem = queue.GetNext(); var dispatchTask = _eventDispatcher.DispatchAsync(nextItem.Event, preTransaction); queueTasks.Add(dispatchTask); // We don't want to log pre-transaction events if (false == preTransaction) { var logTask = _eventLogger.LogEventAsync ( nextItem.AggregateKey, nextItem.AggregateType, nextItem.Event ); queueTasks.Add(logTask); } } await Task.WhenAll(queueTasks).ConfigureAwait(false); }
/// <summary> /// Processes an event queue by dispatching the events /// </summary> /// <param name="preTransaction">True, if pre-transaction handlers required</param> /// <param name="queue">The event queue to process</param> private void ProcessEventQueue ( IEventQueue queue, bool preTransaction = false ) { while (false == queue.IsEmpty()) { var nextItem = queue.GetNext(); _eventDispatcher.Dispatch ( nextItem.Event, preTransaction ); // We don't want to log pre-transaction events if (false == preTransaction) { _eventLogger.LogEvent ( nextItem.AggregateKey, nextItem.AggregateType, nextItem.Event ); } } }