Thanks, Boštjan

Funny :) I'm asking in a context of AsyncGenerator. So, it's how the
listeners are currently invoked (an example based on
OnPersistEventListener):

private void FirePersistAsync(IDictionary copiedAlready, PersistEvent
@event)
{
    using (new SessionIdLoggingContext(SessionId))
    {
        CheckAndUpdateSessionStatus();
        var persistEventListener = listeners.PersistEventListeners;
        for (int i = 0; i < persistEventListener.Length; i++)
        {
            persistEventListener[i].OnPersistAsync(@event, copiedAlready);
        }
    }
}

And this is how the AsyncGenerator converts it to async:

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.

Best Regards,
Alexander

On Sat, May 6, 2017 at 12:15 AM, Boštjan Markežič <
markezic.bost...@gmail.com> wrote:

> Hi Alexander,
>
> Yes, I am using two IPreUpdate event listeners in a single
> ISessionFactory. One
> <https://github.com/maca88/SharperArchitecture/blob/master/Source/SharperArchitecture.DataAccess/NHEventListeners/AuditEntityEventListener.cs>
> is updating the entity audit properties and the other
> <https://github.com/maca88/SharperArchitecture/blob/master/Source/SharperArchitecture.DataAccess/NHEventListeners/ValidatePreInsertUpdateDeleteEventListener.cs>
> is executing the validation for the entity.
> The order somehow matters in this case as I want the validation event
> listener to be executed as last after all properties are populated.
> If you intend to drop support for registering multiple listeners of the
> same type it won't be a problem for me as I can still create my own
> mechanism to spread the event across the system if needed.
> That is just my opinion.
>
> Best Regards,
> Boštjan
>
>
>
> Dne četrtek, 04. maj 2017 15.38.07 UTC+2 je oseba Alexander Zaytsev
> napisala:
>
>> Hi,
>>
>> I want to know if anyone here expects EventListener of* the same type *to
>> run in a particular order.
>>
>> Does anyone have ever implemented and registered two event listeners of *the
>> same type *to the single ISessionFactory?
>>
>> Best Regards,
>> Alexander
>>
> --
>
> ---
> You received this message because you are subscribed to the Google Groups
> "nhibernate-development" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to nhibernate-development+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"nhibernate-development" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to nhibernate-development+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to