Skip to content

Latest commit

History

7 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

SimpleStateMachine

Install

Carthage

github "viablelab/SimpleStateMachine"

Usage

import SimpleStateMachine
enumState{case green
case yellow
case red
}enumAction{case TIMER
}vartrafficLights=StateMachine<State,Action>(
initial:.green,
stateChart:[.green:[.TIMER:.yellow
],.yellow:[.TIMER:.red
],.red:[.TIMER:.green
]])
trafficLights.onTransition({(_ newState:State, _ oldState:State)inprint("Light changed from `\(oldState)` to `\(newState)`")})Timer.scheduledTimer(withTimeInterval:3.0, repeats:true, block:{ timer in
trafficLights.send(.TIMER)})

About

🤖 A simple state machine for Swift

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages