Hi,
Your FSM looks interesting for certain use cases, although I think channels
are the way to go to make thins thread safe in go (passing the structs over
a channel, which is thread safe by nature.)
My FSM is not at all meant to be used in the same cases. It's primary use
is to replace several dependent boolean state variables, for example
open/closed and locked/unlocked for a door. These variables is much better
combined into a simple FSM to track valid combinations (locked and closed
is a strange combination for example.) Here is some sample code on how to
use it:
fsm := NewFSM(
"locked",
Events{
{Name: "unlock", Src: []string{"locked"}, Dst: "unlocked"},
{Name: "open", Src: []string{"unlocked"}, Dst: "open"},
{Name: "close", Src: []string{"open"}, Dst: "unlocked"},
{Name: "lock", Src: []string{"unlocked"}, Dst: "locked"},
},
Callbacks{},
)
fsm.Event("unlock")
fsm.Event("open")
fsm.Event("close")
fsm.Event("lock")
Proper error checking needs to be done on the Event() method to see if the
transition was valid, but I removed it hear to make it easier to read the
example.
I believe both our FSMs have use cases, but I started this thread as an
announcement of my new package so please keep the discussions of
go-statemachine in another thread.
Best Regards,
Max
On Friday, August 23, 2013 12:02:51 PM UTC+2, Ondřej Kupka wrote:Hi,
I've been playing with state machines for my projects as well, although
they are absolutely not the formal FSMs.
You can check it at
https://github.com/tchap/go-statemachine. It's pretty
small but I find it quite useful. It can make your code much easier to read
and understand.
Regards,
Ondra Kupka
--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
For more options, visit
https://groups.google.com/groups/opt_out.