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

org.hammerlab.timing.Interval.scala Maven / Gradle / Ivy

There is a newer version: 5.2.1
Show newest version
package org.hammerlab.timing

object Interval {
  def heartbeat[T](fn: () ⇒ Unit,
                   bodyFn: ⇒ T,
                   intervalS: Int = 1): T = {
    val thread =
      new StoppableThread {
        override def run(): Unit = {
          while (!stopped) {
            Thread.sleep(intervalS * 1000)
            fn()
          }
        }
      }

    thread.start()

    val ret = bodyFn

    thread.end()

    ret
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy