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.

This call can return false only when the BufferOverflow strategy is SUSPENDand there are subscribers collecting this shared flow.

If there are no subscribers, the buffer is not used. Instead, the most recently emitted value is simply stored into the replay cache if one was configured, displacing the older elements there, or dropped if no replay cache was configured. In any case, tryEmit returns true.

This method is thread-safe and can be safely invoked from concurrent coroutines without external synchronization.


Link copied to clipboard