Landry Norris

08/05/2022, 3:02 PM
When I call MutableStateFlow.update {}, isn’t function() called on the same thread? I’m running into an issue when my code looks like the pseudocode in the 🧵 [Solved] function() is called on the same thread, some other code changed my variable that I missed before calling state.update
state.update {
array = array.dropLast(1)
I would expect that the state gets updated with the previous size of the array, but it seems to use the size after I dropLast.


08/05/2022, 4:20 PM
your expectations are correct, something else in your code is different. Minimal reproducible sample will help to understand what's wrong

Landry Norris

08/05/2022, 4:31 PM
I’ll see about getting a minimal reproducible example over the weekend. My code is a bit more complicated than what I showed, but only in so much as state.update is in a function foo and array = array.dropLast is in a function bar.
Just looked more through by code. The function that drops the last element also gets called before state.update, so it is expected that the size is minus one.