Sha256: cda63d887b4505317529009db0dcdbe36fafe563dd9fb8905923763693a26446
Contents?: true
Size: 646 Bytes
Versions: 2
Compression:
Stored size: 646 Bytes
Contents
# frozen_string_literal: true # Released under the MIT License. # Copyright, 2018-2022, by Samuel Williams. module Timers # A collection of timers which may fire at different times class Interval # Get the current elapsed monotonic time. def initialize @total = 0.0 @current = nil end def start return if @current @current = now end def stop return unless @current @total += duration @current = nil end def to_f @total + duration end protected def duration now - @current end protected def now ::Process.clock_gettime(::Process::CLOCK_MONOTONIC) end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
timers-4.3.5 | lib/timers/interval.rb |
timers-4.3.4 | lib/timers/interval.rb |