Lukasz Kalnik
03/29/2021, 3:29 PMSharedFlow
that cancels the flow automatically after all subscribers have left? Something like refCount()
in RxJava.bezrukov
03/29/2021, 3:30 PMSharingStarted.WhileSubscribed()
in .shareIn
operatorLukasz Kalnik
03/29/2021, 3:43 PMonCompletion
then be called?shareIn
. I create a hot flow directly, with MutableSharedFlow
and I need to complete this flow and close underlying resource.elizarov
03/29/2021, 4:20 PMsubscriptionCount
on your hot MutableSharedFlow
(https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.flow/-mutable-shared-flow/subscription-count.html) and track it yourself to implement the corresponding logic. However, it is asynchronous. I don't think there is a reliable way to distinguish the case of "subscribers have not appeared yet" from the case "subscribers have already disappeared".Lukasz Kalnik
03/29/2021, 7:56 PMleaveChannel()
method and every subscriber has to call it, and I will track the subscriber number internally.
Are there any plans to introduce something like refCount()
for SharedFlow
?
http://reactivex.io/documentation/operators/refcount.htmlelizarov
03/29/2021, 8:03 PMLukasz Kalnik
03/29/2021, 8:06 PMursus
03/30/2021, 4:05 AMcallbackFlow { }
builderLukasz Kalnik
03/30/2021, 8:38 AMursus
03/30/2021, 9:21 AM