set

fun set(factory: DispatchLifecycleScopeFactory)
fun set(factory: () -> CoroutineContext)

Override the default MainImmediateCoroutineScope factory, for testing or to include a custom CoroutineContext in production code. This may be done in Application.onCreate

  1. If a DispatcherProvider element isn't present, DefaultDispatcherProvider.get will be added.

  2. If a Job element isn't present, a SupervisorJob will be added.

  3. If the ContinuationInterceptor does not match the one referenced by the possibly new property, it will be updated to match.

Samples

import dispatch.android.espresso.IdlingDispatcherProvider
import dispatch.android.lifecycle.LifecycleScopeFactory
import dispatch.android.lifecycle.MainImmediateContext
import dispatch.core.DispatcherProvider
import dispatch.internal.test.Application
import dispatch.internal.test.MyCustomElement
import dispatch.internal.test.Sample5
import kotlinx.coroutines.SupervisorJob
fun main() { 
   //sampleStart 
   class MyApplication : Application {

  override fun onCreate() {

    LifecycleScopeFactory.set { MyCustomElement() + MainImmediateContext() }
  }
} 
   //sampleEnd
}
import dispatch.android.espresso.IdlingDispatcherProvider
import dispatch.android.lifecycle.LifecycleScopeFactory
import dispatch.android.lifecycle.MainImmediateContext
import dispatch.core.DispatcherProvider
import dispatch.internal.test.Application
import dispatch.internal.test.MyCustomElement
import dispatch.internal.test.Sample5
import kotlinx.coroutines.SupervisorJob
fun main() { 
   //sampleStart 
   class MyEspressoTest {

  @Before
  fun setUp() {

    val dispatcherProvider = IdlingDispatcherProvider()

    LifecycleScopeFactory.set {
      SupervisorJob() + dispatcherProvider + dispatcherProvider.mainImmediate
    }
  }
} 
   //sampleEnd
}

Parameters

factory

sets a custom CoroutineContext factory to be used for all new instance creations until reset. Its Elements will be re-used, except: