Multiplatform (JVM, JS, iOS Kotlin/Native) Kotlin DSL for FSM (finite state machine)
stateMachine(initial = MyState.NOT_LOANED) {
state(MyState.NOT_LOANED) {
edge<MyEvent.PressRental>(MyState.LOCK)
}
state(MyState.ON_LOAN, entry = { /* LED ON */ }, exit = { /* LED OFF */ }) {
state(MyState.LOCK) {
edge<MyEvent.PressUnLock>(MyState.UNLOCK)
edge<MyEvent.PressLock>(MyState.NOT_LOANED, guard = { it.isLongPress })
}
state(MyState.UNLOCK) {
edge<MyEvent.PressLock>(MyState.LOCK, guard = { !it.isLongPress })
}
}
}
for more details, please see FsmTest
repositories {
mavenCentral()
}
def statekVersion = "0.5.0"
// For multiplatform projects
implementation "io.github.tomoya0x00:statek:$statekVersion"
// For jvm projects
implementation "io.github.tomoya0x00:statek-jvm:$statekVersion"