Is there a `shareIn` alt which evaluates lazily? i...
# coroutines
a
Is there a
shareIn
alt which evaluates lazily? i.e.,
Copy code
aFlow = flow(1,2,3).onEach{ println("A $it") }
shared = aFlow.lazyCache()
shared.take(1).forEach{ println("B $it")}
shared.take(2).forEach{ println("C $it")}
would print “A1 B1 A2 C2" … or something to that effect
t
SharedFlow
with a replay cache? A regular flow can be converted using
shareIn
t
Have you tried with
shareIn(scope, SharingStarted.LAZY)
? This ensures that the first suscriber gets all emitted values.
t
without any value for
replay
flows collecting after that will only get the most recent value (whereas the resulting
Flow
from
asFlow
on the
ArrayDeque
will return all values each collection)
perhaps also worth pointing out
Flow.toList