class Timers::Group

A collection of timers which may fire at different times

def after(interval, &block)

the time at which the group was asked to fire timers for.
Call the given block after the given interval. The first argument will be
def after(interval, &block)
	Timer.new(self, interval, false, &block)
end

def cancel

Cancel all timers.
def cancel
	@timers.dup.each(&:cancel)
end

def current_offset

The group's current time.
def current_offset
	@interval.to_f
end

def delay(seconds)

Delay all timers.
def delay(seconds)
	@timers.each do |timer|
		timer.delay(seconds)
	end
end

def every(interval, recur = true, &block)

argument will be the time at which the group was asked to fire timers for.
Call the given block periodically at the given interval. The first
def every(interval, recur = true, &block)
	Timer.new(self, interval, recur, &block)
end

def fire(offset = current_offset)

Fire all timers that are ready.
def fire(offset = current_offset)
	@events.fire(offset)
end

def initialize

def initialize
	@events = Events.new
	
	@timers = Set.new
	@paused_timers = Set.new
	
	@interval = Interval.new
	@interval.start
end

def now_and_after(interval, &block)

argument will be the time at which the group was asked to fire timers for.
Call the given block immediately, and then after the given interval. The first
def now_and_after(interval, &block)
	yield
	after(interval, &block)
end

def now_and_every(interval, recur = true, &block)

argument will be the time at which the group was asked to fire timers for.
Call the given block immediately, and then periodically at the given interval. The first
def now_and_every(interval, recur = true, &block)
	yield
	every(interval, recur, &block)
end

def pause

Pause all timers.
def pause
	@timers.dup.each(&:pause)
end

def resume

Resume all timers.
def resume
	@paused_timers.dup.each(&:resume)
end

def wait

number (fire immediately after return).
like sleep(n), except that n may be nil (sleep forever) or a negative
Wait for the next timer and fire it. Can take a block, which should behave
def wait
	if block_given?
		yield wait_interval
		
		while (interval = wait_interval) && interval > 0
			yield interval
		end
	else
		while (interval = wait_interval) && interval > 0
			# We cannot assume that sleep will wait for the specified time, it might be +/- a bit.
			sleep interval
		end
	end
	
	fire
end

def wait_interval(offset = current_offset)

- +ve: timers waiting to fire
- 0: timers ready to fire
- -ve: timers expired already
- nil: no timers
Interval to wait until when the next timer will fire.
def wait_interval(offset = current_offset)
	handle = @events.first
	handle.time - Float(offset) if handle
end