Skip to content

Instantly share code, notes, and snippets.

@huntc
Created November 20, 2024 00:10
Show Gist options
  • Save huntc/0c4c3aeecff9bf2ecaf9cdec517670ec to your computer and use it in GitHub Desktop.
Save huntc/0c4c3aeecff9bf2ecaf9cdec517670ec to your computer and use it in GitHub Desktop.
Illustration of expressing a state machine using edfsm
#[impl_fsm]
impl Fsm for ClientConnection {
type S = State;
type C = Command;
type E = Event;
type SE = OutputBuffer<SideEffect>;
command!(Disconnected => ConnectClient => ConnectingClient => ClientConnected);
command!(ClientConnected => ConnectServer => ServerConnectionStarted => ConnectingServer);
command!(ClientConnected => HandleCall => CallHandlingDeferred);
command!(ConnectingServer => FailConnectServer => ServerConnectionFailed => ClientConnected);
command!(ConnectingServer => SucceedConnectServer => ServerConnectionSucceeded => HandlingCall | ServerConnected);
command!(ConnectingServer => HandleCall => CallHandlingDeferred);
command!(ServerConnected => HandleCall => CallHandlingStarted => HandlingCall);
command!(ServerConnected => FailConnectServer => ServerConnectionFailed => ClientConnected);
command!(HandlingCall => FailHandlingCall => CallHandlingFailed => HandlingCall | ServerConnected);
command!(HandlingCall => SucceedHandlingCall => CallHandlingSucceeded => HandlingCall | ServerConnected);
command!(HandlingCall => HandleCall => CallHandlingDeferred);
command!(HandlingCall => FailConnectServer => ServerConnectionFailed => ClientConnected);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment