Minsoo Cheong
10/27/2021, 8:42 AMMinsoo Cheong
10/27/2021, 8:44 AMephemient
10/27/2021, 8:45 AMephemient
10/27/2021, 8:47 AM.stateIn()
is cancelled, so is the hot flow, but as long as the scope is still running, the stateflow has a runnable coroutine referencing itMinsoo Cheong
10/27/2021, 8:50 AMMinsoo Cheong
10/27/2021, 8:52 AMephemient
10/27/2021, 8:57 AMonInactive
with subscriptionCount
, as the documentation itself has an example ofephemient
10/27/2021, 8:57 AMMinsoo Cheong
10/27/2021, 9:24 AMyou can emulateI did emulate onInactive in the way you said but wasn't able to find any other way to stop the hot flows there (other than canceling independent scopes) 😿withonInactive
, as the documentation itself has an example ofsubscriptionCount
Minsoo Cheong
10/27/2021, 9:25 AMJoffrey
10/27/2021, 3:28 PMMutableStateFlow
or MutableSharedFlow
. The coroutines @ephemient is mentioning are only launched if you're "converting" a "regular" cold flow into a shared/state flow by using `stateIn()`/`shareIn()` (which do require a scope). This is because those operators start a coroutine that collects the initial cold flow and emit elements to subscribers. Using the mutable variants of those flows is actually pretty cheap: it's just a handle to which you can manually emit stuff, and collectors of these flows would get those emissions (a bit like a channel). Technically these mutable hot flows don't consume any CPU by themselves. However, the MutableSharedFlow
could occupy a bit of memory depending on the buffer size (replay + extra).ephemient
10/27/2021, 9:04 PMJoffrey
10/27/2021, 10:47 PM