Stm State Machine
STM-based state machine with typed states and atomic transitions.
Provides composable, transactional state transitions that can be combined with other STM operations in a single atomic block.
Basic usage:
enum class State { IDLE, RUNNING, STOPPED }
val sm = StmStateMachine.create(State.IDLE)
atomically { with(sm) { transitionIf(State.IDLE, State.RUNNING) } } // true
println(sm.currentState()) // RUNNINGContent copied to clipboard
Composing state transitions with counters:
val sm = StmStateMachine.create(State.IDLE)
val counter = StmCounter.create(0L)
atomically {
val transitioned = with(sm) { transitionIf(State.IDLE, State.RUNNING) }
if (transitioned) {
with(counter) { increment() }
}
}Content copied to clipboard
Types
Link copied to clipboard
object Companion
Factory for StmStateMachine.
Functions
Link copied to clipboard
Reads the current state by running an atomic transaction.
Link copied to clipboard
Unconditionally transitions to the to state within an STM transaction.
Link copied to clipboard