is there a difference between these two? apart fro...
# coroutines
x
is there a difference between these two? apart from the latter being `suspend`ed
Copy code
mutableStateFlow.value = newValue
mutableStateFlow.emit(newValue)
e
the parent interface
MutableSharedFlow
does not have
value
, which is why
emit()
exists. but for
MutableStateFlow
the two have the same behavior. note that
StateFlow
will coalesce emissions regardless of which method you use
👍 2
n
I think there is a difference, .value works only in UI thread where as emit() is a suspend function and can work on the worker thread
nope 2
e
the implementation of
MutableStateFlow.emit()
is exactly
value =
. as in the question, they are identical aside from the
suspend
declaration (and because it doesn't contain any suspend points, there is no coroutine state machine involved)
👍 1