Dontsu
11/25/2024, 7:37 AM.value
and .update()
. Recently, it seems many places are trying to use .update()
instead of .value
due to concurrency issues. However, when I checked the internal code, both eventually call updateState()
, and the updateState()
handles synchronization through a synchronized block. Also, according to the code comments, both .value
and update()
perform operations atomically.
If that's the case, it seems there shouldn't be any reason for race conditions due to multi-threading, so is there a specific reason why we must use update()
?
https://github.com/Kotlin/kotlinx.coroutines/blob/6c6df2b850382887462eeaf51f21f58bd982491d/kotlinx-coroutines-core/common/src/flow/StateFlow.kt#L326Fergus Hewson
11/26/2024, 10:26 PMDontsu
11/27/2024, 4:00 AM