DispatchLifecycleScopeFactory

class DispatchLifecycleScopeFactory(coroutineContextFactory: () -> CoroutineContext)

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)

Functions

Link copied to clipboard
fun create(lifecycle: Lifecycle): DispatchLifecycleScope

Creates a new DispatchLifecycleScope using coroutineContextFactory

Sources

Link copied to clipboard