asyncScopedAction
Launches a coroutine scoped to the state's active lifetime — a UML do activity.
The coroutine starts when the state is entered (after its entry actions complete) and is automatically cancelled when the state is exited. It is re-launched on every subsequent re-entry. The job is also cancelled when the machine is stopped or destroyed, even if a normal state exit transition did not occur (machine stop does not trigger IState.Listener.onExit).
Typical usage — run work until the state is left:
state("polling") {
asyncScopedAction {
while (true) {
pollServer()
delay(1_000)
}
}
}Content copied to clipboard
Requires a machine created with createStateMachine (coroutines support). Throws IllegalArgumentException if called on a machine created with createStdLibStateMachine.