ColdStateRepo
A BaseColdStateRepo that represents its State as a Cold flow. Data will only be set when the state is observed.
This class uses a very simple initialize and deinitialize pattern without changes of state by default
This implementation uses a MutableSharedFlow. If you want to use a cold state repo based on StateFlow, consider ColdStateFlowRepo
Parameters
the type of KalugaState represented by this repo.
the CoroutineContext used to create a coroutine scope for this state machine. Make sure that if you pass a coroutine context that has sequential execution if you do not want simultaneous state changes. The default Main dispatcher meets these criteria.
A Lazy of State in which to store the backing data
See also
Constructors
Properties
Functions
Collects all elements not implementing SpecialFlowValue.NotImportant from a Flow.
Collects all elements not implementing SpecialFlowValue.NotImportant from a Flow up to the first SpecialFlowValue.Last received.
Collects all elements from a Flow up to the first SpecialFlowValue.Last received.
Called when the repo is no longer observed
Filters out all values marked as SpecialFlowValue.NotImportant from a given Flow
Returns first element that is instance of specific type parameter R, or null
if not found
Gets the initial value of the repo
Launches in a given CoroutineContext to change from the current State to a new State. This operation ensures atomic state changes.
Launches in a given CoroutineContext and calls action on the current State. The state is guaranteed not to change during the execution of action. This operation ensures atomic state observations, so the state will not change while the action is being executed.
Changes from the current State to a new State. This operation ensures atomic state changes. The new state is determined by an action, which takes the current State upon starting the state transition and provides a deferred state creation. You are strongly encouraged to use the State provided by the action to determine the new state, to ensure no illegal state transitions occur, as the state may have changed between calling doTakeAndChangeState and the execution of action. If the action returns KalugaState.remain no state transition will occur. Since this operation is atomic, the action should not directly call doTakeAndChangeState itself. If required to do this, handle the additional transition in a separate coroutine.
Transforms a Flow to emit only up to the first SpecialFlowValue.Last received.