Skip to content

Instantly share code, notes, and snippets.

@rcshubhadeep
Created July 21, 2021 17:16
Show Gist options
  • Save rcshubhadeep/e9a444ff3c7c598398d938b1f23b65e2 to your computer and use it in GitHub Desktop.
Save rcshubhadeep/e9a444ff3c7c598398d938b1f23b65e2 to your computer and use it in GitHub Desktop.
Fire Event function
func (s *StateMachine) FireEvent(e Event) error {
presentNode := s.PresentState
it := s.g.From(presentNode.Id)
for it.Next() {
n := s.g.Node(it.Node().ID()).(State)
line := graph.LinesOf(s.g.Lines(presentNode.Id, n.Id))[0].(Link) // There can be one defined path between two distinct states
for key, val := range line.Rules {
k := string(key)
switch k {
case "eq":
if val == e {
s.PresentState = n
return nil
}
default:
fmt.Printf("Sorry, the comparison operator '%s' is not supported\n", k)
return errors.New("UNSUPPORTED_COMPARISON_OPERATOR")
}
}
}
return nil
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment