W3cubDocs

/Kotlin

createCoroutineUnintercepted

Platform and version requirements: JVM (1.3), JS (1.3), Native (1.3)
fun <T> (suspend () -> T).createCoroutineUnintercepted(
    completion: Continuation<T>
): Continuation<Unit>

Creates unintercepted coroutine without receiver and with result type T. This function creates a new, fresh instance of suspendable computation every time it is invoked.

To start executing the created coroutine, invoke resume(Unit) on the returned Continuation instance. The completion continuation is invoked when coroutine completes with result or exception.

This function returns unintercepted continuation. Invocation of resume(Unit) starts coroutine immediately in the invoker's call stack without going through the ContinuationInterceptor that might be present in the completion's CoroutineContext. It is the invoker's responsibility to ensure that a proper invocation context is established. Note that completion of this function may get invoked in an arbitrary context.

Continuation.intercepted can be used to acquire the intercepted continuation. Invocation of resume(Unit) on intercepted continuation guarantees that execution of both the coroutine and completion happens in the invocation context established by ContinuationInterceptor.

Repeated invocation of any resume function on the resulting continuation corrupts the state machine of the coroutine and may result in arbitrary behaviour or exception.

Platform and version requirements: JVM (1.3), JS (1.3), Native (1.3)
fun <R, T> (suspend R.() -> T).createCoroutineUnintercepted(
    receiver: R, 
    completion: Continuation<T>
): Continuation<Unit>

Creates unintercepted coroutine with receiver type R and result type T. This function creates a new, fresh instance of suspendable computation every time it is invoked.

To start executing the created coroutine, invoke resume(Unit) on the returned Continuation instance. The completion continuation is invoked when coroutine completes with result or exception.

This function returns unintercepted continuation. Invocation of resume(Unit) starts coroutine immediately in the invoker's call stack without going through the ContinuationInterceptor that might be present in the completion's CoroutineContext. It is the invoker's responsibility to ensure that a proper invocation context is established. Note that completion of this function may get invoked in an arbitrary context.

Continuation.intercepted can be used to acquire the intercepted continuation. Invocation of resume(Unit) on intercepted continuation guarantees that execution of both the coroutine and completion happens in the invocation context established by ContinuationInterceptor.

Repeated invocation of any resume function on the resulting continuation corrupts the state machine of the coroutine and may result in arbitrary behaviour or exception.

© 2010–2020 JetBrains s.r.o. and Kotlin Programming Language contributors
Licensed under the Apache License, Version 2.0.
https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.coroutines.intrinsics/create-coroutine-unintercepted.html