Is there a way to 'cache'/share a Flow? E.g. I ha...
# coroutines
j
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
I'd use maybe
ConflatedBroadcastChannel
instead, since that caches the latest value
j
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
perhaps storing the relevant data outside in variables would also suit your need, initializing it lazily in the flow block