Overview
KStateMachine is a Kotlin DSL library for creating state machines and statecharts.
The library follows concepts from this two great and well known works:
Workflow
Building blocks (main interfaces) of the library:
StateMachine
- is a collection of states and transitions between them, processes events when startedIState
- states where state machine can go toTransition
- is an operation of moving from one state to anotherEvent
- is a base interface for events which are processed by state machine and may trigger transitions
Working with state machine consists of two major sequental phases:
- Creation with initial setup and starting
- Processing events, on which state machine can switch its states and notify about changes
val machine = createStateMachine(scope) {
// Setup is made in this block ...
}
// After setup and start, it is ready to process events
machine.processEvent(FirstEvent)
// ...
machine.processEvent(OtherEvent)