iosMain.fr.acinq.lightning.utils.AtomicOnce.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of lightning-kmp Show documentation
Show all versions of lightning-kmp Show documentation
A Kotlin Multiplatform implementation of the Lightning Network
package fr.acinq.lightning.utils
import kotlin.native.concurrent.AtomicReference
import kotlin.properties.ReadWriteProperty
import kotlin.reflect.KProperty
internal class AtomicOnce : ReadWriteProperty {
private val ref = AtomicReference(null)
override fun getValue(thisRef: Any?, property: KProperty<*>): T {
return ref.value ?: error("Property ${property.name} should be initialized before get.")
}
override fun setValue(thisRef: Any?, property: KProperty<*>, value: T) {
if (!ref.compareAndSet(null, value)) error("Property ${property.name} has already been initialized.")
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy