Unconfined

object Unconfined : CoroutineDispatcher (source)

A coroutine dispatcher that is not confined to any specific thread. It executes initial continuation of the coroutine right here in the current call-frame and let the coroutine resume in whatever thread that is used by the corresponding suspending function, without mandating any specific threading policy.

Note, that if you need your coroutine to be confined to a particular thread or a thread-pool after resumption, but still want to execute it in the current call-frame until its first suspension, then you can use an optional CoroutineStart parameter in coroutine builders like launch and async setting it to the the value of CoroutineStart.UNDISPATCHED.

Functions

dispatch

fun dispatch(
    context: CoroutineContext,
    block: Runnable
): Unit
fun dispatch(
    context: CoroutineContext,
    block: Runnable
): Unit

Dispatches execution of a runnable block onto another thread in the given context.

isDispatchNeeded

fun isDispatchNeeded(context: CoroutineContext): Boolean

Returns true if execution shall be dispatched onto another thread. The default behaviour for most dispatchers is to return true.

toString

fun toString(): String

Inherited Functions

interceptContinuation

open fun <T> interceptContinuation(
    continuation: Continuation<T>
): Continuation<T>

Returns continuation that wraps the original continuation, thus intercepting all resumptions.

Extension Functions

cancel

fun CoroutineContext.cancel(
    cause: Throwable? = null
): Boolean

Cancels Job of this context with an optional cancellation cause. The result is true if the job was cancelled as a result of this invocation and false if there is no job in the context or if it was already cancelled or completed. See Job.cancel for details.

cancelChildren

fun CoroutineContext.cancelChildren(
    cause: Throwable? = null
): Unit

Cancels all children of the Job in this context with an optional cancellation cause. It does not do anything if there is no job in the context or it has no children. See Job.cancelChildren for details.