You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
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.
The text was updated successfully, but these errors were encountered:
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.
The text was updated successfully, but these errors were encountered: