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

kyo.stats.Gauge.scala Maven / Gradle / Ivy

There is a newer version: 0.8.5
Show newest version
package kyo.stats

import kyo._
import kyo.ios._

case class Gauge(unsafe: Gauge.Unsafe) extends AnyVal {
  def close: Unit > IOs = IOs(unsafe.close())
}

object Gauge {

  abstract class Unsafe {
    def close(): Unit
  }

  val noop: Gauge =
    Gauge(
        new Unsafe {
          def close() = ()
        }
    )

  def all(l: List[Gauge]): Gauge =
    l.filter(_ != noop) match {
      case Nil =>
        noop
      case h :: Nil =>
        h
      case l =>
        Gauge(
            new Unsafe {
              def close() = {
                var c = l
                while (c ne Nil) {
                  c.head.unsafe.close()
                  c = c.tail
                }
              }
            }
        )
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy