DispatchLifecycleScopeFactory
class DispatchLifecycleScopeFactory(coroutineContextFactory: () -> CoroutineContext)
Content copied to clipboard
Factory for DispatchLifecycleScopes. This may be injected into a lifecycle-aware class to provide custom CoroutineContexts.
Samples
import dispatch.android.lifecycle.DispatchLifecycleScopeFactory
import dispatch.internal.test.MyCustomElement
import dispatch.internal.test.Sample5
import dispatch.internal.test.android.LiveDataTest
fun main() {
//sampleStart
@Provides
fun provideFactory(): DispatchLifecycleScopeFactory = DispatchLifecycleScopeFactory {
// other elements are added automatically
MyCustomElement()
}
class MyFragment @Inject constructor(
factory: DispatchLifecycleScopeFactory
) : Fragment() {
val lifecycleScope = factory.create(lifecycle)
init {
lifecycleScope.launchOnStart {
// ...
}
}
}
//sampleEnd
}
Constructors
Link copied to clipboard
fun DispatchLifecycleScopeFactory(coroutineContextFactory: () -> CoroutineContext)
Content copied to clipboard
Functions
Link copied to clipboard
Creates a new DispatchLifecycleScope using coroutineContextFactory