FiniteStateMachine

class FiniteStateMachine<S : Any, E : Any>(initialState: S, stateFunctions: Map<KClass<out S>, Map<KClass<out E>, StateFunction<S, E>>>, defaultEventHandler: (S, E) -> S)

This class represents a Finite State Machine. It can be only in one possible state at a time out of the set of possible states S. It can handle events from the set E.

Parameters

initialState

The initial state.

Constructors

Link copied to clipboard
constructor(initialState: S, stateFunctions: Map<KClass<out S>, Map<KClass<out E>, StateFunction<S, E>>>, defaultEventHandler: (S, E) -> S)

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard
val state: S

The current state.

Link copied to clipboard
val stateFlow: StateFlow<S>

The current state as StateFlow.

Functions

Link copied to clipboard
suspend fun sendEvent(event: E)

Sends an event to the state machine. The entry point to change state.

Link copied to clipboard
fun stay(): S

Keeps the FSM in its current state. Usually used when handling events that don't need to make a transition.