private async Task FirePersistAsync(IDictionary copiedAlready, PersistEvent @event)
{
using (new SessionIdLoggingContext(SessionId))
{
CheckAndUpdateSessionStatus();
var persistEventListener = listeners.PersistEventListeners;
for (int i = 0; i < persistEventListener.Length; i++)
{
await (persistEventListener[i].OnPersistAsync(@event, copiedAlready)).ConfigureAwait(false);
}
}
}
Which is nonoptimal. The code here asynchronously invokes the listeners sequentially one by one.
I would like to invoke them simultaneously instead by Task.WhenAll:
private async Task FirePersistAsync(IDictionary copiedAlready, PersistEvent @event)
{
using (new SessionIdLoggingContext(SessionId))
{
CheckAndUpdateSessionStatus();
var listeners = listeners.PersistEventListeners
.Select(l => l.OnPersistAsync(@event, copiedAlready).ConfigureAwait(false));
await Task.WhenAll(listeners).ConfigureAwait(false);
}
}
So, if anyone is expecting some interdependencies or sequential order of invocations between the listeners we would not be able to do so.