Misleading docs on MutableStateFlow.emit
and MutableStateFlow.tryEmit
methods
#2561
Labels
docs
KDoc and API reference
The Problem
The documentation for the
MutableStateFlow.emit
andMutableStateFlow.tryEmit
functions are misleading. For example, the docs forMutableStateFlow.tryEmit
appear askotlinx.coroutines/kotlinx-coroutines-core/common/src/flow/SharedFlow.kt
Lines 161 to 172 in dda99e2
but in fact that method never blocks and always returns true, regardless of the
BufferOverflow
setting.Why Does the Problem Exist?
In the source code for the actual definition of
MutableStateFlow
kotlinx.coroutines/kotlinx-coroutines-core/common/src/flow/StateFlow.kt
Lines 319 to 326 in dda99e2
the
tryEmit
andemit
methods are overridden so that (as far as I can tell) they never suspend.However, when the
MutableStateFlow
interface is defined, it inherits from theStateFlow
andMutableSharedFlow
interfaces:kotlinx.coroutines/kotlinx-coroutines-core/common/src/flow/StateFlow.kt
Line 158 in dda99e2
The
tryEmit
andemit
functions inherit the documentation fromMutableSharedFlow
despite having their behavior changed in the actual implementation ofMutableStateFlow
A Possible Solution:
Add the overridden functions to the
MutableSharedState
interface with accurate documentation.The text was updated successfully, but these errors were encountered: