Documentation ¶
Overview ¶
Example ¶
package main import ( "fmt" "github.com/cozely/cozely/x/machine" ) func main() { counter := 0 // Define the State Machine var s1, s2, s3 machine.State s1 = func() machine.State { fmt.Println("State 1") return s2 } s2 = func() machine.State { fmt.Println("State 2") return s3 } s3 = func() machine.State { fmt.Println("State 3") if counter > 6 { return nil } return s2 } // Run the State Machine m := s1 for m != nil { counter++ m.Update() } }
Output: State 1 State 2 State 3 State 2 State 3 State 2 State 3
Example (NoAllocations) ¶
package main import ( "fmt" "github.com/cozely/cozely/x/machine" ) var counter int func state1() machine.State { fmt.Println("State 1") return state2 } func state2() machine.State { fmt.Println("State 2") return state3 } func state3() machine.State { fmt.Println("State 3") if counter > 6 { return nil } return state2 } func main() { m := machine.State(state1) for m != nil { counter++ m.Update() } }
Output: State 1 State 2 State 3 State 2 State 3 State 2 State 3
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
Click to show internal directories.
Click to hide internal directories.