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

spice.Initializable.scala Maven / Gradle / Ivy

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