godot.util.ThreadLocalDelegates.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of godot-library-release Show documentation
Show all versions of godot-library-release Show documentation
Contains godot api as kotlin classes and jvm cpp interaction code.
package godot.util
import kotlin.reflect.KProperty
internal class ThreadLocalDelegate(val provider: () -> T) {
private val threadLocal = ThreadLocal.withInitial { provider() }
operator fun getValue(thisRef: Any?, property: KProperty<*>): T = threadLocal.get()
}
internal fun threadLocal(provider: () -> T) = ThreadLocalDelegate(provider)