All Downloads are FREE. Search and download functionalities are using the official Maven repository.

godot.util.ThreadLocalDelegates.kt Maven / Gradle / Ivy

There is a newer version: 0.11.0-4.3
Show newest version
package godot.util

import kotlin.reflect.KProperty


internal class ThreadLocalLazyDelegate(private val provider: () -> T) : Lazy {
    private val threadLocal = ThreadLocal.withInitial { lazy(LazyThreadSafetyMode.NONE, provider) }
    override val value get() = threadLocal.get().value
    override fun isInitialized(): Boolean = threadLocal.get().isInitialized()
}

internal class ThreadLocalDelegate(val provider: () -> T) {
    private val threadLocal = ThreadLocal.withInitial { provider() }
    operator fun getValue(thisRef: Any?, property: KProperty<*>): T = threadLocal.get()
}

internal fun  threadLocalLazy(provider: () -> T) = ThreadLocalLazyDelegate(provider)
internal fun  threadLocal(provider: () -> T) = ThreadLocalDelegate(provider)




© 2015 - 2024 Weber Informatics LLC | Privacy Policy