Skip to content

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

Description

@amkissel

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions