Hey folks :wave:. I have a use-case where I const...
# flow
s
Hey folks 👋. I have a use-case where I construct a Flow that uses resources that can be expensive to initiate (e.g. queries from a database) but eventually completes (is not a continuous stream of data). I was hoping that I could use the
shareIn
operator to ensure the flow is only actually collected once, and subsequently cached. Based on what I've read, due to the fact that
collect
on a
SharedFlow
never actually returns, the recommended pattern is to use some kind of sentinel value to denote the completion of data and combine that with the
takeWhile
operator. Just wanted to check this is indeed the recommended solution.
d
Do you really need Flow if it is not "continuous stream of data"? Anyway, I believe you could collect your Flow with first()/single()/take(1) operator, so it would collect first item and then complete.
s
Hi @dshevliakov while it's not a never-ending stream of data, it's still a stream of data... curious what would be the alternative if not using Flow and also not wanting to wait for processing until all elements have been consumed?
d
sequence ?