// vim: shiftwidth=4 tabstop=4 noexpandtab package main import ( "time" ) type Camera struct { statemachine Machine } func NewCamera() Camera { return Camera{ statemachine: Machine{ name: "camera", initial: "idle", states: StateMap{ "idle": MachineState{ on: TransitionMap{ "take_single_picture": MachineTransition{ to: "single_picture", }, }, }, "single_picture": MachineState{ on: TransitionMap{ "single_picture_taken": MachineTransition{ to: "idle", }, }, }, }, api: make(chan string), state_listeners: make([]*(chan string), 0), hook: runCameraHooks, }, } } func runCameraHooks(last string, next string) { if last == "idle" && next == "single_picture" { // TODO implement launch of python subprocess here go func() { time.Sleep(1 * time.Second) camera.statemachine.SendEvent("single_picture_taken") }() } } func (cam *Camera) run() { cam.statemachine.Run() }