/**
- Executes a block using a given coroutine context.
- /
internal actual inline fun withCoroutineContext(context: CoroutineContext, countOrElement: Any?, block: () -> T): T {
val oldValue = updateThreadContext(context, countOrElement)
try {
} finally {return block()
}restoreThreadContext(context, oldValue)
}
/**
- Executes a block using a context of a given continuation.
- /
internal actual inline fun withContinuationContext(continuation: Continuation<*>, countOrElement: Any?, block: () -> T): T {
val context = continuation.context
val oldValue = updateThreadContext(context, countOrElement)
val undispatchedCompletion = if (oldValue !== NO_THREAD_ELEMENTS) {
} else {// Only if some values were replaced we'll go to the slow path of figuring out where/how to restore them continuation.updateUndispatchedCompletion(context, oldValue)
}null // fast path -- don't even try to find undispatchedCompletion as there's nothing to restore in the context
try {
} finally {return block()
}if (undispatchedCompletion == null || undispatchedCompletion.clearThreadContext()) { restoreThreadContext(context, oldValue) }
}