Reading the following articles,
- MutableStateflow Value Vs Update vs Emit
- https://medium.com/geekculture/atomic-updates-with-mutablestateflow-dc0331724405
- https://proandroiddev.com/make-sure-to-update-your-stateflow-safely-in-kotlin-9ad023db12ba
- https://www.droidcon.com/2021/08/25/make-sure-to-update-your-stateflow-safely-in-kotlin/
I can understand that we can use stateflow update() to update the value atomically.
This is useful when the updated value has a copy()
or some long-running calculations. (API call, room data fetch, etc.)
My question is can we completely replace all the usages of stateflow.value
using update()
or is there any use-case where .value
is the better choice?