Movatterモバイル変換


[0]ホーム

URL:


    kotlinx.coroutines
kotlinx-coroutines-core/kotlinx.coroutines/async

async

fun<T>CoroutineScope.async(context:CoroutineContext =EmptyCoroutineContext,start:CoroutineStart =CoroutineStart.DEFAULT,block:suspendCoroutineScope.() ->T):Deferred<T>(source)

Creates a coroutine and returns its future result as an implementation ofDeferred. The running coroutine is cancelled when the resulting deferred iscancelled. The resulting coroutine has a key difference compared with similar primitives in other languages and frameworks: it cancels the parent job (or outer scope) on failure to enforcestructured concurrency paradigm. To change that behaviour, supervising parent (SupervisorJob orsupervisorScope) can be used.

Coroutine context is inherited from aCoroutineScope, additional context elements can be specified withcontext argument. If the context does not have any dispatcher nor any otherContinuationInterceptor, thenDispatchers.Default is used. The parent job is inherited from aCoroutineScope as well, but it can also be overridden with correspondingcontext element.

By default, the coroutine is immediately scheduled for execution. Other options can be specified viastart parameter. SeeCoroutineStart for details. An optionalstart parameter can be set toCoroutineStart.LAZY to start coroutinelazily. In this case, the resultingDeferred is created innew state. It can be explicitly started withstart function and will be started implicitly on the first invocation ofjoin,await orawaitAll.

Parameters

block

the coroutine code.


[8]ページ先頭

©2009-2025 Movatter.jp