MutableSharedFlow

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.

Inheritors

Properties

Link copied to clipboard

The number of subscribers (active collectors) to this shared flow.

Functions

Link copied to clipboard

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

Link copied to clipboard
abstract suspend override fun emit(value: T)

Emits a value to this shared flow, suspending on buffer overflow.

Link copied to clipboard

Resets the replayCache of this shared flow to an empty state. New subscribers will be receiving only the values that were emitted after this call, while old subscribers will still be receiving previously buffered values. To reset a shared flow to an initial value, emit the value after this call.

Link copied to clipboard
abstract fun tryEmit(value: T): Boolean

Tries to emit a value to this shared flow without suspending. It returns true if the value was emitted successfully (see below). When this function returns false, it means that a call to a plain emit function would suspend until there is buffer space available.