Is it possible to have something like `SharingStar...
# coroutines
n
Is it possible to have something like
SharingStarted.WhileSubscribed()
with the extra feature that if the flow has never emitted, wait for first emission before stopping? In other words, if someone subscribes but then leaves before receiving the first value, wait for it before stop. Looking at source code it seems quite easy to modify
WhileSubscribed
to do this (just add sharedFlow.first()). But we don't have the SharedFlow when creating
SharingStarted
, we only have the upstream flow which means that values in the replay cache are ignored.
d
I feel like this could be done with a custom Flow operator on top of the sharedFlow.
n
Yeah I was just thinking about this, using standard
WhileSubscribed
then launching a coroutine that collects the subscription count and calls first() on first subscriber. Basically add a fake subscription. Not sure if it's the best way
d
Could also make a custom
SharingStarted
where you set the
SharedFlow
later. Not the prettiest though.
­čĹŹ 2