I have a service that returns a StateFlow for subs...
# coroutines
d
I have a service that returns a StateFlow for subscribers interested in a Node in a tree. I would like to close some resources when there are no subscribers. Is
subscriptionCount
a suitable way to track that?
b
how are you creating your flow? if you use
WhileSubscribed
, the flow coroutine will be cancelled when there are no subscribers so you can cleanup that way
d
Ah, that is exactly what I was looking for. Although the flow is actually a MutableStateFlow, though it may make sense to swap that out for something else.