EventFlow icon indicating copy to clipboard operation
EventFlow copied to clipboard

Async ReadModels (IAmReadModelFor)

Open JackHerring opened this issue 7 years ago • 4 comments

Is there any support for async ReadModels? The IAmReadModelFor<TAggregate, in TIdentity, in TEvent> interface has only a void returning method -> I am loathe to implement as async void (not least because fire-and-forget with DB access will inevitably cause problems, but also error-handling and order of execution). I need to do some async work before applying my ReadModel changes, though.

Is there a way to do this or is this a case of roll-your-own?

JackHerring avatar Jan 28 '19 21:01 JackHerring

It looks like async void isn't even an option here as the caller of Apply will expect the Model to be in a Db-writable state immediately after the call returns which will be at the point of the first await. Only way to do this at the moment appears to be blocking on the Task completing with Wait()/GetAwaiter().GetResult()

JackHerring avatar Jan 28 '19 23:01 JackHerring

@JackHerring the original idea as not to have any complex operations in the read model updates. However, as you have pointed out, this is not always the case and indeed async void is a no go as the read model update will continue without the async operation being awaited.

I'll add it as a feature request as see if its possible to do anything about it. It might be that an additional interface as I would really dislike having to introduce such a breaking change to the API.

rasmus avatar Feb 01 '19 07:02 rasmus

@frankebersoll thank you for adding this feature, very much appreciated.

JackHerring avatar Feb 12 '19 19:02 JackHerring

Closing this as its implemented in #585

rasmus avatar Dec 29 '19 23:12 rasmus