asyncIO
fun <T> CoroutineScope.asyncIO(context: CoroutineContext = EmptyCoroutineContext, start: CoroutineStart = CoroutineStart.DEFAULT, block: suspend CoroutineScope.() -> T): Deferred<T>
Content copied to clipboard
Creates a coroutine and returns its future result as an implementation of Deferred.
Uses the iodispatcher.
The specific dispatcherProvider
instance to be used is determined after the context parameter has been folded into the receiver's context.
The selected DispatcherProvider is essentially the first non-null result from:
the context parameter
the receiver CoroutineScope's coroutineContext
DefaultDispatcherProvider.get Extracts the DispatcherProvider from the CoroutineScope receiver
Samples
import dispatch.core.asyncDefault
import dispatch.core.asyncIO
import dispatch.core.asyncMain
import dispatch.core.asyncMainImmediate
import dispatch.core.asyncUnconfined
import dispatch.internal.test.Sample5
import dispatch.internal.test.dispatcherName
import dispatch.internal.test.someDispatcherProvider
import io.kotest.matchers.shouldBe
import kotlinx.coroutines.runBlocking
fun main() {
//sampleStart
runBlocking(someDispatcherProvider) {
dispatcherName() shouldBe "runBlocking thread"
asyncIO {
dispatcherName() shouldBe "io"
}.join()
}
//sampleEnd
}
See also
async