-
Notifications
You must be signed in to change notification settings - Fork 768
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
OnEntry of the "terminating" state is not called when previous state is async #364
Comments
I think this is a problem with using async await with void methods. The CLR will create its own state machine for every async await, and it will return code execution early if it can. The
|
If you wait a bit then you'll see the expected output:
Output: |
Of course OnEntry of Terminated state will be called in this case, but it's not as a state machine supposed to work, IMO. Fire should be either blocking till state machine completely changed the state or be async and provide a possibility to wait state changing. |
I agree, the non-Async version of Fire should not return early. And the Sync version should be Wait()-able... |
I had another look at this, and I think I was wrong. When you call |
using System;
using System.Threading;
using System.Threading.Tasks;
using NUnit.Framework;
using Stateless;
namespace DeckTracker.Model.Tests
{
public class StateMachineTest
{
private const string InitialState = "InitialState";
private const string WorkState = "WorkState";
private const string StartWorkTrigger = "StartWorkTrigger";
private const string TerminatedState = "Terminated";
private const string TerminateTrigger = "Terminate";
}
}
Test output:
Start working
working...
working...
working...
How do I wait till state machine handled "Terminated" state correctly?
The text was updated successfully, but these errors were encountered: