Parent

Class/Module Index [+]

Quicksearch

Timers::Wait

An exclusive, monotonic timeout class.

Attributes

duration[R]
remaining[R]

Public Class Methods

for(duration, &block) click to toggle source
# File lib/timers/wait.rb, line 7
def self.for(duration, &block)
  if duration
    timeout = self.new(duration)
    
    timeout.while_time_remaining(&block)
  else
    while true
      yield(nil)
    end
  end
end
new(duration) click to toggle source
# File lib/timers/wait.rb, line 19
def initialize(duration)
  @duration = duration
  @remaining = true
end

Public Instance Methods

while_time_remaining(&block) click to toggle source

Yields while time remains for work to be done:

# File lib/timers/wait.rb, line 28
def while_time_remaining(&block)
  @interval = Hitimes::Interval.new
  @interval.start
  
  while time_remaining?
    yield @remaining
  end
ensure
  @interval.stop
  @interval = nil
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.