class Timers::Interval

A collection of timers which may fire at different times

Public Class Methods

new() click to toggle source

Get the current elapsed monotonic time.

# File lib/timers/interval.rb, line 27
def initialize
        @total = 0.0
        @current = nil
end

Public Instance Methods

start() click to toggle source
# File lib/timers/interval.rb, line 32
def start
        return if @current
        
        @current = now
end
stop() click to toggle source
# File lib/timers/interval.rb, line 38
def stop
        return unless @current
        
        @total += duration
        
        @current = nil
end
to_f() click to toggle source
# File lib/timers/interval.rb, line 46
def to_f
        @total + duration
end

Protected Instance Methods

duration() click to toggle source
# File lib/timers/interval.rb, line 50
          def duration
        now - @current
end
now() click to toggle source
# File lib/timers/interval.rb, line 54
          def now
        ::Process.clock_gettime(::Process::CLOCK_MONOTONIC)
end