Daniele B
09/16/2020, 5:10 PMStateFlow
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.Thomas
09/16/2020, 5:59 PMStateFlow
cannot be frozen yet. See https://github.com/Kotlin/kotlinx.coroutines/issues/2138Daniele B
09/16/2020, 6:18 PMThomas
09/16/2020, 6:19 PMThomas
09/16/2020, 6:22 PMThomas
09/16/2020, 6:23 PMDaniele B
09/16/2020, 6:29 PM