https://kotlinlang.org logo
Title
w

William Reed

12/14/2021, 2:57 PM
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

Adam Powell

12/14/2021, 3:05 PM
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

William Reed

12/14/2021, 3:06 PM
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

Adam Powell

12/14/2021, 3:07 PM
I would try to pick a sensible default value, yes.
w

William Reed

12/14/2021, 3:07 PM
ty
a

Adam Powell

12/14/2021, 3:07 PM
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