diff --git a/kotlinx-coroutines-core/jvm/src/CoroutineContext.kt b/kotlinx-coroutines-core/jvm/src/CoroutineContext.kt index e08b805295..34f245ede0 100644 --- a/kotlinx-coroutines-core/jvm/src/CoroutineContext.kt +++ b/kotlinx-coroutines-core/jvm/src/CoroutineContext.kt @@ -181,6 +181,14 @@ internal actual class UndispatchedCoroutineactual constructor ( */ private var threadStateToRecover = ThreadLocal>() + init { + // TODO explain this + if (uCont.context[ContinuationInterceptor] !is CoroutineDispatcher) { + val values = updateThreadContext(context, null) + threadStateToRecover.set(context to values) + } + } + fun saveThreadContext(context: CoroutineContext, oldValue: Any?) { threadStateToRecover.set(context to oldValue) }