natario1
04/11/2021, 10:47 AMSharingStarted.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.Dominaezzz
04/11/2021, 11:04 AMnatario1
04/11/2021, 11:08 AMWhileSubscribed
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 wayDominaezzz
04/11/2021, 11:17 AMSharingStarted
where you set the SharedFlow
later. Not the prettiest though.