createStateMachine

suspend fun createStateMachine(scope: CoroutineScope, name: String? = null, childMode: ChildMode = ChildMode.EXCLUSIVE, start: Boolean = true, creationArguments: CreationArguments = buildCreationArguments {}, init: suspend BuildingStateMachine.() -> Unit): StateMachine

Suspendable analog of createStdLibStateMachine function, with Kotlin Coroutines support. This is preferred function. Use this one especially if you are going to use Kotlin Coroutines library from KStateMachine callbacks.

Parameters

scope

be careful while working with threaded scopes as KStateMachine classes are not thread-safe. Usually you should use only single threaded scopes, for example:

CoroutineScope(newSingleThreadContext("single threaded context"))

Note that all calls to created machine instance should be done only from that thread.