Files
legado/modules/rhino1.7.3/src/main/java/com/script/rhino/ContextElement.kt
T
2024-01-28 17:09:25 +08:00

26 lines
748 B
Kotlin

package com.script.rhino
import kotlinx.coroutines.ThreadContextElement
import kotlin.coroutines.CoroutineContext
class ContextElement : ThreadContextElement<Any?> {
companion object Key : CoroutineContext.Key<ContextElement>
override val key: CoroutineContext.Key<ContextElement>
get() = Key
private val contextHelper: Any? = VMBridgeReflect.contextLocal.get()
override fun updateThreadContext(context: CoroutineContext): Any? {
val oldState = VMBridgeReflect.contextLocal.get()
VMBridgeReflect.contextLocal.set(contextHelper)
return oldState
}
override fun restoreThreadContext(context: CoroutineContext, oldState: Any?) {
VMBridgeReflect.contextLocal.set(oldState)
}
}