dotnet-state-machine / stateless

A simple library for creating state machines in C# code
Other
5.41k stars 746 forks source link

Bugfix: execute OnEntryFromAsync actions from FireAsync #532

Closed mclift closed 1 year ago

mclift commented 1 year ago

Proposed resolution for issue #531.

It seems we missed a mistake in #511 in class AsyncFrom<TTriggerType> such that a call to the async method ExecuteAsync would invoke the synchronous Execute, which intentionally throws an InvalidOperationException.

Additionally, the implementation of AsyncFrom<TTriggerType>.ExecuteAsync(Transition, object[]) does not return the task queued to execute the entry action, and instead returns Task.CompletedTask, making it impossible for the caller to await completion of the entry action.

This PR changes ExecuteAsync so that it invokes the async action and returns the queued task.