-
Notifications
You must be signed in to change notification settings - Fork 788
Open
Description
Hi, I have a state machine with 2 states: Idle and Pinging.
Pinging state permits reentry, to loop the ping forever.
The problem is that when I call _Machine.Fire(Triggers.Ping)
, the call does not exit.
Is there a better way to handle looping states?
Here a sample code:
// See https://aka.ms/new-console-template for more information
using Stateless;
var _MachineSynch = new StateMachine<State, Triggers>(State.Idle);
_MachineSynch.Configure(State.Idle)
.Permit(Triggers.Ping, State.Pinging)
.OnEntry(OnDisconnect);
_MachineSynch.Configure(State.Pinging)
.PermitReentry(Triggers.Ping)
.Permit(Triggers.Disconnect, State.Idle)
.OnEntry(OnPing);
void OnDisconnect()
{
Task.Delay(100).Wait();
Console.WriteLine("Disconnected");
}
void OnPing()
{
Console.WriteLine("Pinging...");
Task.Delay(1000).Wait();
Console.WriteLine("PingED. repinging");
_MachineSynch.Fire(Triggers.Ping);
Console.WriteLine("PingED. repinged");
}
//start synch
_MachineSynch.Fire(Triggers.Ping);
Console.WriteLine("FIRED"); //NEVER ARRIVES HERE
public enum State
{
Idle,
Pinging,
}
public enum Triggers
{
//Connect,
Ping,
Disconnect,
}
Metadata
Metadata
Assignees
Labels
No labels