Downscoping the shared flow to avoid leaking downstream

This commit is contained in:
Adam Brown 2022-12-29 20:42:15 +00:00
parent ac2c975d3f
commit c6ad944994
2 changed files with 6 additions and 1 deletions

View File

@ -11,6 +11,7 @@ import androidx.compose.ui.platform.LocalLifecycleOwner
import androidx.lifecycle.Lifecycle import androidx.lifecycle.Lifecycle
import androidx.lifecycle.LifecycleEventObserver import androidx.lifecycle.LifecycleEventObserver
import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.SharedFlow import kotlinx.coroutines.flow.SharedFlow
import kotlinx.coroutines.flow.launchIn import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.onEach import kotlinx.coroutines.flow.onEach
@ -27,6 +28,10 @@ class StartScope(private val scope: CoroutineScope) {
fun <T> SharedFlow<T>.launch(onEach: suspend (T) -> Unit) { fun <T> SharedFlow<T>.launch(onEach: suspend (T) -> Unit) {
this.onEach(onEach).launchIn(scope) this.onEach(onEach).launchIn(scope)
} }
fun <T> Flow<T>.launch(onEach: suspend (T) -> Unit) {
this.onEach(onEach).launchIn(scope)
}
} }
interface EffectScope { interface EffectScope {

@ -1 +1 @@
Subproject commit ea31ab26de443ed5e6bb67ce594e3ce8d5f04ff3 Subproject commit a0425cb9196ba728309b1f2ab616df6ad1168b90