withState

abstract suspend fun withState(block: suspend S.() -> Unit)

Obtain the current state and operate on it without changing the state.

  • This function does NOT update the state, for that, use updateState.

  • This function will suspend until all previous withState or updateState invocations are finished if StoreConfiguration.atomicStateUpdates are enabled.

  • If you want to operate on a state of particular subtype, use the typed version of this function.

  • If you wish to ignore plugins and thread-safety of state updates in favor of greater performance, see ImmediateStateReceiver.updateStateImmediate

This function is reentrant, which means, if you call:

withState {
withState { }
}

you will not get a deadlock even if the transaction is serializable.