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

kyo.concurrent.adders.scala Maven / Gradle / Ivy

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

import kyo._
import kyo.ios._

import java.util.concurrent.atomic.{DoubleAdder => JDoubleAdder}
import java.util.concurrent.atomic.{LongAdder => JLongAdder}

object adders {

  object Adders {
    val initLong: LongAdder > IOs     = IOs(new LongAdder(new JLongAdder()))
    val initDouble: DoubleAdder > IOs = IOs(new DoubleAdder(new JDoubleAdder()))
  }

  class LongAdder private[adders] (private val ref: JLongAdder) extends AnyVal {

    def add(v: Long): Unit > IOs = IOs(ref.add(v))
    def decrement: Unit > IOs    = IOs(ref.decrement())
    def increment: Unit > IOs    = IOs(ref.increment())
    def get: Long > IOs          = IOs(ref.sum())
    def reset: Unit > IOs        = IOs(ref.reset())
  }

  class DoubleAdder private[adders] (private val ref: JDoubleAdder) extends AnyVal {

    def add(v: Double): Unit > IOs = IOs(ref.add(v))
    def get: Double > IOs          = IOs(ref.sum())
    def reset: Unit > IOs          = IOs(ref.reset())
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy