State machine
Page contents
Create state machine
A state machine can be created with one of those factory functions:
createStateMachine()suspendable version (fromkstatemachine-coroutinesartifact), the best choice by default.createStateMachineBlocking()blocking version (fromkstatemachine-coroutinesartifact)createStdLibStateMachine()- creates StateMachine instance without Kotlin Coroutines support (fromkstatemachineartifact)
val machine = createStateMachine(
scope, //
"Traffic lights" // Optional name is convenient for logging debugging and export
) {
// Set up state machine ...
}
By default, factory functions start state machine. You can control it using start argument. All overloads accept optional argument CreationArguments which allows to change some options. Use buildCreationArguments() function to provide it.
Subsequent samples will use createStateMachine() function, but you can choose that one which fits your needs.