Class: Timers::Wait

### Home Classes Methods

### In Files

- lib/timers/wait.rb

### Parent

Object

### Methods

- ::for
- ::new
- #while_time_remaining

### Class/Module Index

Quicksearch

- Timers
- Timers::Events
- Timers::Events::Handle
- Timers::Group
- Timers::Timer
- Timers::Wait

No matching classes.

# 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.