flowOnMainImmediate
Extracts the DispatcherProvider from the coroutineContext
of the collector coroutine, then uses its DispatcherProvider.mainImmediate property to call flowOn(theDispatcher)
, and returns the result.
Samples
import dispatch.core.flowOnDefault
import dispatch.core.flowOnIO
import dispatch.core.flowOnMain
import dispatch.core.flowOnMainImmediate
import dispatch.core.flowOnUnconfined
import dispatch.internal.test.Sample5
import dispatch.internal.test.dispatcherName
import dispatch.internal.test.someDispatcherProvider
import io.kotest.matchers.shouldBe
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.flow.collect
import kotlinx.coroutines.flow.flow
import kotlinx.coroutines.runBlocking
fun main() {
//sampleStart
runBlocking(someDispatcherProvider) {
dispatcherName() shouldBe "runBlocking thread"
flow {
dispatcherName() shouldBe "main immediate"
emit(Unit)
}.flowOnMainImmediate() // switch to the "mainImmediate" dispatcher for everything upstream
.collect() // collect the flow from the "main" dispatcher
}
//sampleEnd
}
See also
flowOn