Movatterモバイル変換


[0]ホーム

URL:


Dispatch
dispatch-core/dispatch.core/launchDefault

launchDefault

funCoroutineScope.launchDefault(context:CoroutineContext =EmptyCoroutineContext,start:CoroutineStart =CoroutineStart.DEFAULT,block:suspendCoroutineScope.() ->Unit):Job
Content copied to clipboard

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

Uses thedefaultdispatcher.

The specificdispatcherProvider instance to be used is determinedafter thecontext parameter has beenfolded into the receiver's context.

The selectedDispatcherProvider is essentially the first non-null result from:

Samples

import dispatch.core.launchDefaultimport dispatch.core.launchIOimport dispatch.core.launchMainimport dispatch.core.launchMainImmediateimport dispatch.core.launchUnconfinedimport dispatch.internal.test.Sample5import dispatch.internal.test.dispatcherNameimport dispatch.internal.test.someDispatcherProviderimport io.kotest.matchers.shouldBeimport kotlinx.coroutines.runBlockingfun main() {    //sampleStart    runBlocking(someDispatcherProvider) {    dispatcherName() shouldBe "runBlocking thread"    launchDefault {      dispatcherName() shouldBe "default"    }.join()  }    //sampleEnd}

See also

launch

Sources

Link copied to clipboard
© 2022 CopyrightGenerated bydokka

[8]ページ先頭

©2009-2025 Movatter.jp