DefaultDispatcherProvider

object DefaultDispatcherProvider

Holder singleton for a DispatcherProvider instance.

If CoroutineScope.dispatcherProvider or CoroutineContext.dispatcherProvider is referenced in a CoroutineContext which does not have one, it will use a default defined by this object.

Samples

import dispatch.core.DefaultDispatcherProvider
import dispatch.core.DispatcherProvider
import dispatch.core.MainImmediateCoroutineScope
import dispatch.core.mainImmediateDispatcher
import dispatch.internal.test.Sample5
import io.kotest.matchers.shouldBe
import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.ObsoleteCoroutinesApi
import kotlinx.coroutines.newSingleThreadContext
import kotlinx.coroutines.test.resetMain
import kotlinx.coroutines.test.setMain
import org.junit.jupiter.api.AfterEach
import org.junit.jupiter.api.BeforeEach
fun main() { 
   //sampleStart 
   val custom = CustomDispatcherProvider()
DefaultDispatcherProvider.set(custom)

val scope = MainImmediateCoroutineScope()

scope.mainImmediateDispatcher shouldBe custom.mainImmediate
DefaultDispatcherProvider.get().mainImmediate shouldBe custom.mainImmediate 
   //sampleEnd
}

Functions

Link copied to clipboard
fun get(): DispatcherProvider

Returns the current configured default DispatcherProvider

Link copied to clipboard
operator fun invoke(): DispatcherProvider

Default implementation of DispatcherProvider which simply delegates to the corresponding properties in the Dispatchers singleton.

Link copied to clipboard
fun set(value: DispatcherProvider)

Atomically sets a default DispatcherProvider instance.

Sources

Link copied to clipboard