Is there any way to get a Sharable Flow that ends?...
# coroutines
b
Is there any way to get a Sharable Flow that ends? I have a slow producer with an end. And I have multiple slow consumers that need all the produced items. My current solution is convert that Flow in a List and then start the consumers. But I'm losing time because some consumers can start it's work as soon as the producer emits the first element.
m
Catch the upstream completion with
onComplete { … }
and emit a special value downstream that signals the end of the stream. Downstream you can use
.takeWhile {}
to stop the downstream flow if the shared flow has emitted the special value.