reset

fun DefaultDispatcherProvider.reset()

Resets the singleton DispatcherProvider instance to the true default. This default instance delegates to the Dispatchers singleton object properties.

Samples

import dispatch.core.DefaultDispatcherProvider
import dispatch.core.DispatcherProvider
import dispatch.internal.test.Sample5
import dispatch.test.reset
import io.kotest.matchers.shouldBe
import io.kotest.matchers.shouldNotBe
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)

DefaultDispatcherProvider.get() shouldBe custom

DefaultDispatcherProvider.reset()

val default = DefaultDispatcherProvider.get()

default shouldNotBe custom

default.default shouldBe Dispatchers.Default
default.io shouldBe Dispatchers.IO
default.main shouldBe Dispatchers.Main
default.mainImmediate shouldBe Dispatchers.Main.immediate
default.unconfined shouldBe Dispatchers.Unconfined 
   //sampleEnd
}

See also

Sources

Link copied to clipboard