DefaultStatesManager

open class DefaultStatesManager<T : State>(repo: DefaultStatesManagerRepo<T> = InMemoryDefaultStatesManagerRepo(), onStartContextsConflictResolver: suspend (current: T, new: T) -> Boolean = { _, _ -> false }, onUpdateContextsConflictResolver: suspend (old: T, new: T, currentNew: T) -> Boolean = { _, _, _ -> false }) : StatesManager<T> (source)

Parameters

repo

This repo will be used as repository for storing states. All operations with this repo will happen BEFORE any event will be sent to onChainStateUpdated, onStartChain or onEndChain. By default, will be used InMemoryDefaultStatesManagerRepo or you may create custom DefaultStatesManagerRepo and pass as repo parameter

onStartContextsConflictResolver

Receive current State and the state passed with startChain. In case when this callback will return true, currently placed on the State.context will be replaced by new state with endChain with current state

onUpdateContextsConflictResolver

Receive old State, new one and the state currently placed on new State.context key. In case when this callback will returns true, the state placed on State.context of new will be replaced by new state by using endChain with that state

Constructors

Link copied to clipboard
constructor(repo: DefaultStatesManagerRepo<T>, onContextsConflictResolver: suspend (old: T, new: T, currentNew: T) -> Boolean)
constructor(repo: DefaultStatesManagerRepo<T> = InMemoryDefaultStatesManagerRepo(), onStartContextsConflictResolver: suspend (current: T, new: T) -> Boolean = { _, _ -> false }, onUpdateContextsConflictResolver: suspend (old: T, new: T, currentNew: T) -> Boolean = { _, _, _ -> false })

Properties

Link copied to clipboard
open override val onChainStateUpdated: Flow<Pair<T, T>>
Link copied to clipboard
open override val onEndChain: Flow<T>
Link copied to clipboard
open override val onStartChain: Flow<T>

Functions

Link copied to clipboard
open suspend override fun endChain(state: T)

Ends chain with context from state. In case when State.context of state is absent, state should be just ignored

Link copied to clipboard
open suspend override fun getActiveStates(): List<T>
Link copied to clipboard
open suspend override fun startChain(state: T)

Starts chain with state as first State. May returns false in case of State.context of state is already busy by the other State

Link copied to clipboard
open suspend override fun update(old: T, new: T)

Must set current set using State.context