File tree Expand file tree Collapse file tree 2 files changed +21
-2
lines changed
Expand file tree Collapse file tree 2 files changed +21
-2
lines changed Original file line number Diff line number Diff line change @@ -16,6 +16,7 @@ func main() {
1616 fsm.Events {
1717 {Name : "produce" , Src : []string {"idle" }, Dst : "idle" },
1818 {Name : "consume" , Src : []string {"idle" }, Dst : "idle" },
19+ {Name : "remove" , Src : []string {"idle" }, Dst : "idle" },
1920 },
2021 fsm.Callbacks {
2122 "produce" : func (_ context.Context , e * fsm.Event ) {
@@ -27,7 +28,12 @@ func main() {
2728 if ok {
2829 fmt .Println ("message = " + message .(string ))
2930 }
30-
31+ },
32+ "remove" : func (_ context.Context , e * fsm.Event ) {
33+ e .FSM .DeleteMetadata ("message" )
34+ if _ , ok := e .FSM .Metadata ("message" ); ! ok {
35+ fmt .Println ("message removed" )
36+ }
3137 },
3238 },
3339 )
@@ -48,4 +54,11 @@ func main() {
4854
4955 fmt .Println (fsm .Current ())
5056
57+ err = fsm .Event (context .Background (), "remove" )
58+ if err != nil {
59+ fmt .Println (err )
60+ }
61+
62+ fmt .Println (fsm .Current ())
63+
5164}
Original file line number Diff line number Diff line change 2121//
2222// Fysom for Python
2323// https://github.com/oxplot/fysom (forked at https://github.com/mriehl/fysom)
24- //
2524package fsm
2625
2726import (
@@ -270,6 +269,13 @@ func (f *FSM) SetMetadata(key string, dataValue interface{}) {
270269 f .metadata [key ] = dataValue
271270}
272271
272+ // DeleteMetadata deletes the dataValue in metadata by key
273+ func (f * FSM ) DeleteMetadata (key string ) {
274+ f .metadataMu .Lock ()
275+ delete (f .metadata , key )
276+ f .metadataMu .Unlock ()
277+ }
278+
273279// Event initiates a state transition with the named event.
274280//
275281// The call takes a variable number of arguments that will be passed to the
You can’t perform that action at this time.
0 commit comments