class Timers::Wait

An exclusive, monotonic timeout class.

def self.for(duration, &block)

def self.for(duration, &block)
	if duration
		timeout = new(duration)
		
		timeout.while_time_remaining(&block)
	else
		# If there is no "duration" to wait for, we wait forever.
		loop do
			yield(nil)
		end
	end
end

def initialize(duration)

def initialize(duration)
	@duration = duration
	@remaining = true
end

def time_remaining?

def time_remaining?
	@remaining = (@duration - @interval.to_f)
	
	@remaining > 0
end

def while_time_remaining

Yields while time remains for work to be done:
def while_time_remaining
	@interval = Interval.new
	@interval.start
	
	yield @remaining while time_remaining?
ensure
	@interval.stop
	@interval = nil
end