launchDefault

fun CoroutineScope.launchDefault(context: CoroutineContext = EmptyCoroutineContext, start: CoroutineStart = CoroutineStart.DEFAULT, block: suspend CoroutineScope.() -> Unit): Job

Launches a new coroutine without blocking the current thread and returns a reference to the coroutine as a Job. The coroutine is cancelled when the resulting job is cancelled.

Uses the defaultdispatcher.

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:

Samples

import dispatch.core.launchDefault
import dispatch.core.launchIO
import dispatch.core.launchMain
import dispatch.core.launchMainImmediate
import dispatch.core.launchUnconfined
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"

    launchDefault {

      dispatcherName() shouldBe "default"
    }.join()
  } 
   //sampleEnd
}

See also

launch

Sources

Link copied to clipboard