StateMachine

interface StateMachine<S, E : StateEvent>

Interface for a state machine that manages state transitions through events.

A state machine provides controlled state management with event-driven transitions, lifecycle management, and observer notifications. This interface is designed to be coroutine-friendly while requiring zero external dependencies.

Parameters

S

The type of states in the state machine

E

The type of events that can trigger transitions

Inheritors

Properties

Link copied to clipboard
abstract val currentState: S

The current state of the state machine.

Link copied to clipboard
abstract val isRunning: Boolean

True if the state machine is currently running (started and not stopped).

Link copied to clipboard
abstract val isStarted: Boolean

True if the state machine has been started at least once.

Link copied to clipboard
abstract val observerCount: Int

Returns the number of registered observers.

Functions

Link copied to clipboard
abstract fun addObserver(observer: StateObserver<S>): Boolean

Adds an observer to receive state change notifications.

Link copied to clipboard
abstract fun clearObservers()

Removes all observers.

Link copied to clipboard
abstract fun removeObserver(observer: StateObserver<S>): Boolean

Removes an observer from receiving state change notifications.

Link copied to clipboard
abstract fun send(event: E): Boolean

Sends an event to the state machine for processing.

Link copied to clipboard
abstract fun start()

Starts the state machine.

Link copied to clipboard
abstract fun stop()

Stops the state machine.