Dragan Vojvodić
10/31/2022, 3:09 PMinline fun <T> Fragment.collectFlowSafely(
flowToCollect: Flow<T>,
repeatState: Lifecycle.State = Lifecycle.State.STARTED,
crossinline value: (T) -> Unit
) {
viewLifecycleOwner.lifecycleScope.launch {
viewLifecycleOwner.repeatOnLifecycle(repeatState) {
flowToCollect.collect {
value(it)
}
}
}
}
Would this way of collecting flow be safe from cancellation point of view? i.e. Would cancel the collection when the view is no longer visible etc?