Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

class AsyncDispatcher : IAriDispatcher improperly uses 'await Task.Run(action)'. Because methods are 'events' with void return, await does not work #99

Open
amkissel opened this issue Apr 30, 2023 · 1 comment

Comments

@amkissel
Copy link

amkissel commented Apr 30, 2023

If setting 'public const EventDispatchingStrategy DefaultEventDispatchingStrategy = EventDispatchingStrategy.AsyncTask;' in ARIClient.cs, the expected behavior is that each event method handler that is coded in user code, is run as a task, with an 'await' on that task to finish, before another event, of the same type, is processed.

However, the 'public class BaseAriClient : IAriEventClient' (in file ARIClient.cs), where all of the various user handler references are stored in this class (ex: OnStasisStartEvent) are defined as 'events', which are void return types by definition. The 'sealed class AsyncDispatcher : IAriDispatcher' class, 'public async void QueueAction(Action action)' method (in AsyncDispatcher.cs) implements this=> 'await Task.Run(action);' call, which by definition requires something to be returned for the 'await' to work.

But since the user's event handlers are defined as 'void', the await Task.Run(action); returns immediately and moves on, before the user's event handler has completed. This causes the user's code to be re-entered asynchronously if there are multiple events of the same type that need to be handled by the same user's event handler.

@adamreed90
Copy link
Collaborator

@seiggy Do you know if this has been corrected in your #77 PR?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants