brabo-hi
07/29/2023, 9:18 PMStateFlow
.E.g
val uiState = MutableStateFlow(MyUiState.Empty)
uiState.value = MyUiState.Loading
uiState.update { MyUiState.Loading }
What is the difference using uiState.value
and uiState.update
s3rius
07/29/2023, 9:27 PMvalue
atomically, but if you want a read+write to be one atomic operation you can use update
. So if you do flow.value = flow.value + 1
there's a chance that you get the wrong result if another thread modifies flow.value
at the same time. With flow.update { it + 1 }
you're guaranteed that flow's value gets increased by 1.brabo-hi
07/29/2023, 9:48 PM