https://kotlinlang.org logo
Title
d

dan.the.man

04/01/2021, 4:54 PM
If I have a Stateflow is there a difference between
emit(newValue)
and
value = newValue
like there was for post/value in Livedata? I'm not seeing any documentation, I think we're supposed to use Emit, but using value = appears to be working in my code?
z

Zach Klippenstein (he/him) [MOD]

04/01/2021, 5:40 PM
Emit will suspend in some cases. The kdoc on the function explains more. Setting the value property never suspends.
However MutableStateFlow never experiences back pressure (it always has “drop oldest” behavior), so emit will never suspend. It’s just there because MutableStateFlow extends MutableSharedFlow
It’s much more idiomatic to use the value setter when working with MSF
d

dan.the.man

04/01/2021, 5:42 PM
Cool, thanks for the info!
o

Orhan Tozan

04/01/2021, 7:14 PM
@Zach Klippenstein (he/him) [MOD]
However MutableStateFlow never experiences back pressure (it always has “drop oldest” behavior), so emit will never suspend. It's just there because MutableStateFlow extends MutableSharedFlow
Inheritance🙁
z

Zach Klippenstein (he/him) [MOD]

04/01/2021, 8:21 PM
yea 😞