Skip to content

Zekiee/go-fsm

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 

Repository files navigation

go-fsm

A simple finite state machine for Golang

Basic Example

From examples/fsm-test.go:

doorCtrl := fsm.NewFSM(
		[]fsm.Transition{
			{"openDoor", []string{"Closed"}, "Opened"},
			{"closeDoor", []string{"Opened"}, "Closed"},
			{"lockDoor", []string{"UnLocked", "Closed"}, "Locked"},
			{"unLockDoor", []string{"Locked", "Opened"}, "UnLocked"},
		}, []fsm.CCallBack{
			onLeaveClosed,
			onLeaveOpened,
			onLeaveLocked,
			onLeaveUnlocked,
			onEnterClosed,
			onEnterOpened,
			onEnterLocked,
			onEnterUnlocked,
			onTransition,
			onFailed,
		},
		"Opened")


	doorCtrl.Trans("closeDoor")
	doorCtrl.Trans("closeDoor")
	doorCtrl.Trans("openDoor")

will get output like this:

enter main

onLeaveOpened [Opened  closeDoor]
onEnterClosed [Closed Opened closeDoor]
onFailed [Closed Opened closeDoor]
onLeaveClosed [Closed Opened openDoor]
onEnterOpened [Opened Closed openDoor]

leave main

About

A simple finite state machine for Golang

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages