MutableStateFlow

A mutable StateFlow that provides a setter for value. An instance of MutableStateFlow with the given initial value can be created using MutableStateFlow(value) constructor function.

See the StateFlow documentation for details on state flows. Note that all emission-related operators, such as value's setter, emit, and tryEmit, are conflated using Any.equals.

Not stable for inheritance

The MutableStateFlow interface is not stable for inheritance in 3rd party libraries, as new methods might be added to this interface in the future, but is stable for use. Use the MutableStateFlow() constructor function to create an implementation.

Properties

Link copied to clipboard
abstract override var value: T

The current value of this state flow.

Functions

Link copied to clipboard

Represents this mutable state flow as a read-only state flow.

Link copied to clipboard
abstract fun compareAndSet(expect: T, update: T): Boolean

Atomically compares the current value with expect and sets it to update if it is equal to expect. The result is true if the value was set to update and false otherwise.

Link copied to clipboard
inline fun <T> MutableStateFlow<T>.getAndUpdate(function: (T) -> T): T

Updates the MutableStateFlow.value atomically using the specified function of its value, and returns its prior value.

Link copied to clipboard
inline fun <T> MutableStateFlow<T>.update(function: (T) -> T)

Updates the MutableStateFlow.value atomically using the specified function of its value.

Link copied to clipboard
inline fun <T> MutableStateFlow<T>.updateAndGet(function: (T) -> T): T

Updates the MutableStateFlow.value atomically using the specified function of its value, and returns the new value.