https://kotlinlang.org logo
#coroutines
Title
# coroutines
j

jeff

11/08/2019, 5:58 PM
Is there a way to 'cache'/share a Flow? E.g. I have
Copy code
flow { expensiveNetworkOperation() }
and I want to collect that flow repeatedly. What's the best way to prevent duplicating the expensiveNetworkOperation() call?
n

nrobi

11/08/2019, 6:15 PM
I'd use maybe
ConflatedBroadcastChannel
instead, since that caches the latest value
j

jeff

11/08/2019, 6:16 PM
interesting, ill look into that. But I may have more than one value in the flow (e.g. a paginated network call)
looks like ArrayBroadcastChannel might be what I need
o

octylFractal

11/08/2019, 7:22 PM
perhaps storing the relevant data outside in variables would also suit your need, initializing it lazily in the flow block