Async calls in the ConnectToPersistentSubscription EventAppeared action

For example, is there any benefit to:

private async void OnEventReceived(EventStorePersistentSubscriptionBase subscription, ResolvedEvent resolvedEvent)
{
var thing = new Thing();
var result = await _repository.SaveAsync(thing);

}

``

versus just waiting/blocking the current thread:

private void OnEventReceived(EventStorePersistentSubscriptionBase subscription, ResolvedEvent resolvedEvent)

{

var thing = new Thing();

var result = _repository.SaveAsync(thing).Result; // or .Wait() etc...

}

``

Will EventStore make use of the original thread if the async operation is awaited or is this just a bad idea? Assuming if this was intended to be Async the EventAppeared would be a function that returned a Task…not an action.

When providing an “EventAppeared” method for ConnectToPersistentSubscription I have calls on the EventReceived that are async calls. Like saving a record to Elastic etc… Is there anything to be gained by making the event appeared method async and awaiting these calls, or is the expected pattern that I will simply “.Wait()” the contained async calls.

Use manual acking then ack in your async callback...

Greg, do you see that pattern as advantageous over blocking until the handler finishes?

Thanks,

Yes for async handlers as they can be async (and you get retry mechanisms etc)

Cool thanks