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

japgolly.scalajs.react.callback.Timer.scala Maven / Gradle / Ivy

package japgolly.scalajs.react.callback

trait Timer {
  type Handle
  def delay(ms: Long)(proc: => Any): Handle
  def cancel(handle: Handle): Unit
}

object Timer {

  implicit object RealTimer extends Timer {
    import scala.scalajs.js.timers._

    override type Handle = SetTimeoutHandle

    override def delay(ms: Long)(proc: => Any): SetTimeoutHandle =
      setTimeout(ms.toDouble)(proc)

    override def cancel(handle: SetTimeoutHandle): Unit =
      try
        clearTimeout(handle)
      catch {
        case _: Throwable =>
      }
  }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy