i want to expose a `StateFlow` in my viewmodel tha...
# coroutines
w
i want to expose a
StateFlow
in my viewmodel that is backed by the
Flow
based jetpack DataStore. Any recommendations on how to do this without using
runBlocking
to get the initial value? i was thinking of calling a
suspend fun
to do this in my view model
init
, but then the
StateFlow
would not be available as soon as it is requested by the view
a
This API is forcing you to be very explicit about blocking your main thread for I/O if that's what you really want
w
agree, but is there a canonical way to solve this without blocking the main thread? perhaps just using a sensible default value for my case instead?
a
I would try to pick a sensible default value, yes.
w
ty
a
If you can't, you can always show a loading screen of sorts until you have a value loaded
Or any other kind of UI placeholder to keep responsive