Created
July 21, 2021 17:16
-
-
Save rcshubhadeep/e9a444ff3c7c598398d938b1f23b65e2 to your computer and use it in GitHub Desktop.
Fire Event function
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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