forked from looplab/fsm
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* added data feature * added commit for NoDataError * added NoDataError * added data.go to demonstrate usage of data feature * renamed data to metadata * removed key level locks from metadata * removed NoDataError Co-authored-by: Aman Sai Ankam <aman.sai@PP-C02CP5SYMD6M.local>
- Loading branch information
1 parent
882719a
commit 5a52348
Showing
3 changed files
with
77 additions
and
10 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// +build ignore | ||
|
||
package main | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/looplab/fsm" | ||
) | ||
|
||
func main() { | ||
fsm := fsm.NewFSM( | ||
"idle", | ||
fsm.Events{ | ||
{Name: "produce", Src: []string{"idle"}, Dst: "idle"}, | ||
{Name: "consume", Src: []string{"idle"}, Dst: "idle"}, | ||
}, | ||
fsm.Callbacks{ | ||
"produce": func(e *fsm.Event) { | ||
e.FSM.SetMetadata("message", "hii") | ||
fmt.Println("produced data") | ||
}, | ||
"consume": func(e *fsm.Event) { | ||
message, ok := e.FSM.Metadata("message") | ||
if ok { | ||
fmt.Println("message = " + message.(string)) | ||
} | ||
|
||
}, | ||
}, | ||
) | ||
|
||
fmt.Println(fsm.Current()) | ||
|
||
err := fsm.Event("produce") | ||
if err != nil { | ||
fmt.Println(err) | ||
} | ||
|
||
fmt.Println(fsm.Current()) | ||
|
||
err = fsm.Event("consume") | ||
if err != nil { | ||
fmt.Println(err) | ||
} | ||
|
||
fmt.Println(fsm.Current()) | ||
|
||
} |
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
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