The DriverEventQueue is a simple queue that holds TimedEvent instances in order to maintain the schedule of upcoming events.
Initialize a DriverEventQueue.
# File lib/god/driver.rb, line 95 def initialize @shutdown = false @events = [] @monitor = Monitor.new @resource = @monitor.new_cond end
Clear the queue.
Returns nothing.
# File lib/god/driver.rb, line 153 def clear @events.clear end
Returns true if the queue is empty, false if not.
# File lib/god/driver.rb, line 146 def empty? @events.empty? end
Returns the Integer length of the queue.
# File lib/god/driver.rb, line 158 def length @events.length end
Wait until the queue has something due, pop it off the queue, and return it.
Returns the popped event.
# File lib/god/driver.rb, line 116 def pop @monitor.synchronize do if @events.empty? raise ThreadError, "queue empty" if @shutdown @resource.wait else delay = @events.first.at - Time.now @resource.wait(delay) if delay > 0 end @events.shift end end
Add an event to the queue, wake any waiters if what we added needs to happen sooner than the next pending event.
Returns nothing.
# File lib/god/driver.rb, line 134 def push(event) @monitor.synchronize do @events << event @events.sort! # If we've sorted the events and found the one we're adding is at # the front, it will likely need to run before the next due date. @resource.signal if @events.first == event end end
Generated with the Darkfish Rdoc Generator 2.