MutableSharedFlow

interface MutableSharedFlow<T> : SharedFlow<T> , FlowCollector<T>

A mutable SharedFlow that provides functions to emit values to the flow. An instance of MutableSharedFlow with the given configuration parameters can be created using MutableSharedFlow(...) constructor function.

See the SharedFlow documentation for details on shared flows.

MutableSharedFlow is a SharedFlow that also provides the abilities to emit a value, to tryEmit without suspension if possible, to track the subscriptionCount, and to resetReplayCache.

Concurrency

All methods of shared flow are thread-safe and can be safely invoked from concurrent coroutines without external synchronization.

Not stable for inheritance

The MutableSharedFlow 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 MutableSharedFlow(...) constructor function to create an implementation.

Functions

emit
Link copied to clipboard
common
abstract suspend override fun emit(value: T)
Emits a value to this shared flow, suspending on buffer overflow if the shared flow was created with the default BufferOverflow.SUSPEND strategy.
resetReplayCache
Link copied to clipboard
common
abstract fun resetReplayCache()
Resets the replayCache of this shared flow to an empty state.
tryEmit
Link copied to clipboard
common
abstract fun tryEmit(value: T): Boolean
Tries to emit a value to this shared flow without suspending.

Properties

subscriptionCount
Link copied to clipboard
common
abstract val subscriptionCount: StateFlow<Int>
The number of subscribers (active collectors) to this shared flow.

Inheritors

MutableStateFlow
Link copied to clipboard

Extensions

asSharedFlow
Link copied to clipboard
common
fun <T> MutableSharedFlow<T>.asSharedFlow(): SharedFlow<T>
Represents this mutable shared flow as a read-only shared flow.

Sources

common source
Link copied to clipboard