In Files

Parent

Included Modules

Class/Module Index [+]

Quicksearch

Timers::Timer

An individual timer set to fire a given proc at a given time

Attributes

interval[R]
offset[R]
recurring[R]

Public Class Methods

new(timers, interval, recurring = false, &block) click to toggle source
# File lib/timers.rb, line 108
def initialize(timers, interval, recurring = false, &block)
  @timers, @interval, @recurring = timers, interval, recurring
  @block  = block
  @offset = nil

  reset
end

Public Instance Methods

<=>(other) click to toggle source
# File lib/timers.rb, line 116
def <=>(other)
  @offset <=> other.offset
end
call(offset = @timers.current_offset) click to toggle source
Alias for: fire
cancel() click to toggle source

Cancel this timer

# File lib/timers.rb, line 121
def cancel
  @timers.cancel self
end
continue() click to toggle source

Continue this timer

# File lib/timers.rb, line 152
def continue
  @timers.continue self
end
delay(seconds) click to toggle source

Extend this timer

# File lib/timers.rb, line 126
def delay(seconds)
  @timers.delete self
  @offset += seconds
  @timers.add self
end
fire(offset = @timers.current_offset) click to toggle source

Fire the block

# File lib/timers.rb, line 140
def fire(offset = @timers.current_offset)
  reset(offset) if recurring
  @block.call
end
Also aliased as: call
inspect() click to toggle source

Inspect a timer

# File lib/timers.rb, line 157
def inspect
  str = "#<Timers::Timer:#{object_id.to_s(16)} "
  offset = @timers.current_offset

  if @offset
    if @offset >= offset
      str << "fires in #{@offset - offset} seconds"
    else
      str << "fired #{offset - @offset} seconds ago"
    end

    str << ", recurs every #{interval}" if recurring
  else
    str << "dead"
  end

  str << ">"
end
pause() click to toggle source

Pause this timer

# File lib/timers.rb, line 147
def pause
  @timers.pause self
end
reset(offset = @timers.current_offset) click to toggle source

Reset this timer

# File lib/timers.rb, line 133
def reset(offset = @timers.current_offset)
  @timers.cancel self if @time
  @offset = Float(offset) + @interval
  @timers.add self
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.