I have a question about `StateFlow` on Kotlin/Nati...
# kotlin-native
d
I have a question about
StateFlow
on Kotlin/Native. Let’s say StateFlow is holding/passing an immutable data object, and it’s collected on the iOS side on
Dispatchers.Main
, to be used with SwiftUI. On the Application Logic side, I’m processing/setting the new StateFlow values (by using the Kotlin
copy
function), inside a coroutine. My question is: according to the current Kotlin/Native multithreading system, should such coroutine where I am processing/setting the new StateFlow values run on
Dispatchers.Main
or it can also use a background thread (e.g. Dispatchers.Default)? Being the value immutable, I wonder if
StateFlow
is able to provide thread safety under the hood, without having to care what is the thread where the new value is set.
t
Unfortunately
StateFlow
cannot be frozen yet. See https://github.com/Kotlin/kotlinx.coroutines/issues/2138
d
@Thomas I thought you don’t need to freeze data which is immutable. In my case I am just dealing with immutable data.
t
If you want to access something from multiple threads, it needs to be frozen
The problem here is that StateFlow itself does not support freezing, so it's not only about its values
d
ok I see, I hoped it was a sophisticated structure that could move immutable data around from one thread to the other one, without hassles