Chris Grigg
05/25/2021, 2:38 PMflowWithLifecycle, which looks like it was introduced in a newer version of lifecycle than I have installed. Is flowWithLifecycle the best way or can/should one still use shareIn or stateIn with a hot flow to control the collection behavior in a lifecycle-aware way?Adam Powell
05/25/2021, 2:40 PMAdam Powell
05/25/2021, 2:41 PMChris Grigg
05/25/2021, 2:41 PMAdam Powell
05/25/2021, 2:44 PMChris Grigg
05/25/2021, 2:44 PMAdam Powell
05/25/2021, 2:44 PMChris Grigg
05/25/2021, 2:46 PMAdam Powell
05/25/2021, 2:48 PMChris Grigg
05/25/2021, 2:49 PMChris Grigg
05/25/2021, 2:50 PMAdam Powell
05/25/2021, 2:50 PMAdam Powell
05/25/2021, 2:51 PMChris Grigg
05/25/2021, 2:51 PMAdam Powell
05/25/2021, 2:53 PMAdam Powell
05/25/2021, 2:55 PMChris Grigg
05/25/2021, 2:55 PMAdam Powell
05/25/2021, 2:56 PMflow {}, channelFlow {} and callbackFlow {} APIs from kotlinx.coroutines; none of them are compose-specificAdam Powell
05/25/2021, 2:57 PMChris Grigg
05/25/2021, 2:59 PMcollect makes it come to life, which, like you said… I’m already nope-ing out of.Adam Powell
05/25/2021, 3:00 PM.stateIn with WhileSubscribed and the like, since then the flow collection is scoped to the union of all current subscribers, at which point you want the subscribers to be lifecycle-aware.Chris Grigg
05/25/2021, 3:00 PMChris Grigg
05/25/2021, 3:02 PMAdam Powell
05/25/2021, 3:03 PMChris Grigg
05/25/2021, 3:04 PMAdam Powell
05/25/2021, 3:04 PMAdam Powell
05/25/2021, 3:05 PMChris Grigg
05/25/2021, 3:06 PMAdam Powell
05/25/2021, 3:07 PMChris Grigg
05/25/2021, 3:08 PMAdam Powell
05/25/2021, 3:08 PMChris Grigg
05/25/2021, 3:09 PMChris Grigg
05/25/2021, 3:10 PMAdam Powell
05/25/2021, 3:11 PMChris Grigg
05/25/2021, 3:11 PMChris Grigg
05/25/2021, 3:11 PMChris Grigg
05/25/2021, 3:12 PMAdam Powell
05/25/2021, 3:12 PMAdam Powell
05/25/2021, 3:12 PMChris Grigg
05/25/2021, 3:13 PMshareIn down in the UI since the providers will be cold, right?Chris Grigg
05/25/2021, 3:14 PMChris Grigg
05/25/2021, 3:14 PMChris Grigg
05/25/2021, 3:17 PMChris Grigg
05/25/2021, 3:17 PMAdam Powell
05/25/2021, 3:18 PMshareIn is only useful when it's ok for any given consumer to miss events because it arrived late, or unsubscribed and resubscribed for some reason. shareIn represents a diffusion of responsibility for consumers and people tend to tie themselves in knots trying to fix the problems they created by adding that diffusion of responsibility.Adam Powell
05/25/2021, 3:22 PMChris Grigg
05/25/2021, 3:23 PMChris Grigg
05/25/2021, 3:24 PMSharedFlow to channelFlow would switch us from a hot flow to a cold flow, so that changes the lifecycle equation for all consumers, right?Adam Powell
05/25/2021, 3:25 PMChris Grigg
05/25/2021, 3:26 PMChris Grigg
05/25/2021, 3:27 PMChris Grigg
05/25/2021, 3:27 PMAdam Powell
05/25/2021, 3:28 PM.flowWithLifecycle or repeatOnLifecycle blocks for collectorsAdam Powell
05/25/2021, 3:28 PM.collectAsState() for event streams, only for actual state 🙂Chris Grigg
05/25/2021, 3:29 PMChris Grigg
05/25/2021, 3:30 PMAdam Powell
05/25/2021, 3:30 PMChris Grigg
05/25/2021, 3:30 PMChris Grigg
05/25/2021, 3:30 PMAdam Powell
05/25/2021, 3:30 PMChris Grigg
05/25/2021, 3:30 PMChris Grigg
05/25/2021, 3:31 PMChris Grigg
05/25/2021, 3:33 PMSharedFlow or StateFlow if not in a case like this?Adam Powell
05/25/2021, 3:40 PMshareIn or stateIn , at points of last-mile info distribution of data originating from cold flows, especially when combined with WhileSubscribed. MutableSharedFlow is useful for FYI types of events where it truly doesn't matter if no one was listening and things get dropped. MutableStateFlow I use almost never when compose's mutableStateOf is available instead, but some data access patterns can make it the better choice. (For example, compose's Recomposer exposes its current operational state as a StateFlow and it wouldn't benefit in the slightest from using snapshot state instead; there would be a number of drawbacks in terms of immediacy of change dispatch among other things.)Chris Grigg
05/25/2021, 3:42 PMChris Grigg
05/25/2021, 3:44 PMChris Grigg
05/25/2021, 3:48 PMchannelFlow over a hot SharedFlow for incoming sensor messages because it forces consumers to play an active role (or at least acknowledge) in their lifecycle handling. Consumers should use flowWithLifecycle or repeatOnLifecycle .
• If for some reason my composable function is consuming a hot flow, it’s not necessary to add any additional lifecycle handling since I’m skipping around that by using a hot flow in the first place. The composable function will stop consuming the flow when it goes out of scope.Adam Powell
05/25/2021, 3:49 PMChris Grigg
05/25/2021, 3:49 PMChris Grigg
05/25/2021, 3:50 PM