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

com.wavesplatform.metrics.package.scala Maven / Gradle / Ivy

The newest version!
package com.wavesplatform

import kamon.metric.Timer

package object metrics {
  final implicit class TimerExt(private val timer: Timer) extends AnyVal {
    def measure[T](f: => T): T =
      measureWithFilter(f)(_ => true)

    def measureSuccessful[LeftT, RightT](f: => Either[LeftT, RightT]): Either[LeftT, RightT] =
      measureWithFilter(f)(_.isRight)

    def measureOptional[T](f: => Option[T]): Option[T] =
      measureWithFilter(f)(_.isDefined)

    private[this] def measureWithFilter[T](f: => T)(filter: T => Boolean): T = {
      val startedTimer = timer.start()
      val result       = f
      if (filter(result)) startedTimer.stop()
      result
    }
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy