https://kotlinlang.org logo
Title
a

Andrew Gazelka

12/28/2020, 12:39 AM
Is there a
shareIn
alt which evaluates lazily? i.e.,
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

Tijl

12/28/2020, 7:02 AM
SharedFlow
with a replay cache? A regular flow can be converted using
shareIn
t

tseisel

12/28/2020, 7:56 AM
Have you tried with
shareIn(scope, SharingStarted.LAZY)
? This ensures that the first suscriber gets all emitted values.
t

Tijl

12/28/2020, 8:04 AM
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