Created
June 14, 2021 13:45
-
-
Save blaZ3/8606e22e6a12fb85a0231cf8e74e047d to your computer and use it in GitHub Desktop.
ManagedCoroutineScope
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import androidx.lifecycle.LifecycleCoroutineScope | |
import kotlinx.coroutines.CoroutineScope | |
import kotlinx.coroutines.Job | |
import kotlin.coroutines.CoroutineContext | |
internal interface ManagedCoroutineScope : CoroutineScope { | |
fun launch(block: suspend CoroutineScope.() -> Unit): Job | |
} | |
internal class LifecycleManagedCoroutineScope( | |
private val lifecycleCoroutineScope: LifecycleCoroutineScope | |
) : ManagedCoroutineScope { | |
override val coroutineContext: CoroutineContext | |
get() = lifecycleCoroutineScope.coroutineContext | |
override fun launch(block: suspend CoroutineScope.() -> Unit): Job = | |
lifecycleCoroutineScope.launchWhenCreated(block) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment