io.pixeloutlaw.minecraft.spigot.ResettableLazy.kt Maven / Gradle / Ivy
The 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
}
}