How can an initial value be loaded from a `suspend...
# coroutines
z
How can an initial value be loaded from a
suspend
function using something similar to
.scan(..)
with a
SharedFlow
?
Copy code
.scan(loadInitialValueAsynchronously()) { .. }
I’m effectively trying to replace an
actor
with a
SharedFlow
.
The best solution I’ve come up with is to use a
Deferred<SharedFlow<State>
and emit that as `
Copy code
flow { emitAll(deferredStateFlow.await()) }
seems a little un-ergonomic though? is there a better solution?
I think
Copy code
.shareIn(
  this,
  SharingStarted.Eagerly, // begin observing immediately!
  replay = 1
)
can be replaced with:
Copy code
.stateIn(this)
which makes it a little nicer