Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit b4e1aba3 authored by Lynn Yeh's avatar Lynn Yeh Committed by Android (Google) Code Review
Browse files

Merge "Return Job in collectLatestWithLifecycle" into 24D1-dev

parents 8cadc83b 367dcd84
Loading
Loading
Loading
Loading
+4 −5
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ import androidx.lifecycle.Lifecycle
import androidx.lifecycle.LifecycleOwner
import androidx.lifecycle.lifecycleScope
import androidx.lifecycle.repeatOnLifecycle
import kotlinx.coroutines.Job
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.collectLatest
import kotlinx.coroutines.flow.combine
@@ -61,10 +62,8 @@ fun <T> Flow<T>.collectLatestWithLifecycle(
    lifecycleOwner: LifecycleOwner,
    minActiveState: Lifecycle.State = Lifecycle.State.STARTED,
    action: suspend (value: T) -> Unit,
) {
    lifecycleOwner.lifecycleScope.launch {
): Job = lifecycleOwner.lifecycleScope.launch {
    lifecycleOwner.repeatOnLifecycle(minActiveState) {
        collectLatest(action)
    }
}
}