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

Commit bcc59ec1 authored by Chaohui Wang's avatar Chaohui Wang Committed by Android (Google) Code Review
Browse files

Merge "Return Job in collectLatestWithLifecycle" into main

parents e9afaba4 9ebfba9a
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)
    }
}
}