Doesn't matter, you can update from it from any context.
Use the most readable variant, it can be even
tryEmit
, but I personally prefer 'C' variant
🙌 2
Neon
09/10/2023, 1:22 PM
if it's a state with state flow, it will not suspend your execution
🙌 1
x
xoangon
09/10/2023, 2:45 PM
I’d stick with #B for most of the cases, as it uses
synchronized
to resolve concurrent state updates. Take a look at the source code for *`MutableStateFlow<T>.update` here*
You could end up with race conditions when using #C
There’s no need for a coroutine to update the state, option #A introduces unnecessary overhead
🙌 1
u
uli
09/25/2023, 2:46 PM
For #B, did you mean:
Copy code
_uiState.update { previousState -> newState }
uli
09/25/2023, 2:48 PM
I think, there is no advantage of #B over #C as long as you are not referencing previousState