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

iosMain.fr.acinq.lightning.utils.AtomicOnce.kt Maven / Gradle / Ivy

There is a newer version: 1.8.4
Show newest version
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