jvmMain.ResettableDelegate.kt Maven / Gradle / Ivy
package org.openrndr.utils
import java.util.concurrent.atomic.AtomicReference
import kotlin.reflect.KProperty
// via https://stackoverflow.com/a/53921217/130168
actual class ResettableDelegate actual constructor(private val initializer: () -> T) {
private val lazyRef: AtomicReference> = AtomicReference(
lazy(
initializer
)
)
actual operator fun getValue(thisRef: Any?, property: KProperty<*>): T {
return lazyRef.get().getValue(thisRef, property)
}
actual fun reset() {
lazyRef.set(lazy(initializer))
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy