Hi folks, what is the difference of `consumeAsFlow...
# coroutines
s
Hi folks, what is the difference of
consumeAsFlow
and
receiveAsFlow
, and what the different use cases of both?
s
I read it but I don't understand very well :S
z
`consumeAsFlow`: “The resulting flow can be collected just once and throws IllegalStateException when trying to collect it more than once.”
receiveAsFlow
will not throw if it’s collected multiple times. Instead, items will be fanned out so each element will only be delivered to one collector.
It's important to note that neither of these operators does any multicasting/sharing, which is why they have limitations - either they can guarantee a collector gets all elements (by preventing any other collectors), or they can just not make any guarantees and let items get delivered to whichever collector happens to get scheduled first.
🙏🏼 1