MCPcopy
hub / github.com/looplab/fsm / ExampleFSM_Transition

Function ExampleFSM_Transition

fsm_test.go:1014–1040  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

1012}
1013
1014func ExampleFSM_Transition() {
1015 fsm := NewFSM(
1016 "closed",
1017 Events{
1018 {Name: "open", Src: []string{"closed"}, Dst: "open"},
1019 {Name: "close", Src: []string{"open"}, Dst: "closed"},
1020 },
1021 Callbacks{
1022 "leave_closed": func(_ context.Context, e *Event) {
1023 e.Async()
1024 },
1025 },
1026 )
1027 err := fsm.Event(context.Background(), "open")
1028 if e, ok := err.(AsyncError); !ok && e.Err != nil {
1029 fmt.Println(err)
1030 }
1031 fmt.Println(fsm.Current())
1032 err = fsm.Transition()
1033 if err != nil {
1034 fmt.Println(err)
1035 }
1036 fmt.Println(fsm.Current())
1037 // Output:
1038 // closed
1039 // open
1040}
1041
1042func TestEventAndCanInGoroutines(t *testing.T) {
1043 fsm := NewFSM(

Callers

nothing calls this directly

Calls 5

EventMethod · 0.95
CurrentMethod · 0.95
TransitionMethod · 0.95
NewFSMFunction · 0.85
AsyncMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…