()
| 1012 | } |
| 1013 | |
| 1014 | func 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 | |
| 1042 | func TestEventAndCanInGoroutines(t *testing.T) { |
| 1043 | fsm := NewFSM( |
nothing calls this directly
no test coverage detected
searching dependent graphs…