spice.Initializable.scala Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of spice-core_3 Show documentation
Show all versions of spice-core_3 Show documentation
Core functionality leveraged and shared by most other sub-projects of YouI.
package spice
import cats.effect.IO
import java.util.concurrent.atomic.AtomicInteger
trait Initializable {
private val status = new AtomicInteger(0)
def isInitialized: Boolean = status.get() == 2
final def init(): IO[Boolean] = if (status.compareAndSet(0, 1)) {
initialize().map { _ =>
status.set(2)
true
}
} else {
IO.pure(false)
}
protected def initialize(): IO[Unit]
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy