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

io.pixeloutlaw.minecraft.spigot.ResettableLazy.kt Maven / Gradle / Ivy

There is a newer version: 9.0.4
Show newest version
package io.pixeloutlaw.minecraft.spigot

internal fun  resettableLazy(value: () -> T) = ResettableLazy(value)

internal class ResettableLazy(private val initializer: () -> T) : Lazy {
    private var cached: T? = null
    override val value: T
        get() {
            return cached ?: return initializer().also { cached = it }
        }

    override fun isInitialized(): Boolean = cached != null

    fun reset() {
        cached = null
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy