tuweni / org.apache.tuweni.concurrent.coroutines / kotlinx.coroutines.CoroutineScope / asyncResult

asyncResult

fun <T> CoroutineScope.asyncResult(context: CoroutineContext = Dispatchers.Default, start: CoroutineStart = CoroutineStart.DEFAULT, block: suspend CoroutineScope.() -> T): AsyncResult<T> (source)

Starts new co-routine and returns its result as an implementation of AsyncResult. The running co-outine is cancelled when the resulting future is cancelled or otherwise completed.

Co-routine context is inherited from a CoroutineScope, additional context elements can be specified with context argument. If the context does not have any dispatcher nor any other ContinuationInterceptor, then Dispatchers.Default is used. The parent job is inherited from a CoroutineScope as well, but it can also be overridden with corresponding coroutineContext element.

By default, the co-routine is immediately scheduled for execution. Other options can be specified via start parameter. See CoroutineStart for details. A value of CoroutineStart.LAZY is not supported (since AsyncResult framework does not provide the corresponding capability) and produces IllegalArgumentException.

See newCoroutineContext for a description of debugging facilities that are available for newly created co-routine.

Parameters

context - Additional to CoroutineScope.coroutineContext context of the coroutine.

start - Co-routine start option. The default value is CoroutineStart.DEFAULT.

block - The co-routine code.