that it won't get any new messages, so `collect`s terminate?
s
Sam
02/07/2024, 6:09 PM
Nope, shared flows can never terminate.
c
Casey Brooks
02/07/2024, 6:10 PM
No. From the docs, “Shared flow never completes.” This is by design, as SharedFlows are meant for sharing values to multiple subscribers, and are not designed as a general-purpose communication mechanism with a “lifecycle”.
If you want the collectors to respond to some “close” event, you’ll need to pass a value as a “close token” into the SharedFlow and collectors must use
takeWhile
to respond to it themselves. Alternatively, use a Channel, which can be explicitly closed.