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.