This commit is contained in:
Horis
2024-01-28 17:09:25 +08:00
parent b9d6616ca6
commit e3aa72b315
22 changed files with 350 additions and 160 deletions
@@ -0,0 +1,25 @@
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)
}
}