@private A time-sorted list of objects. Thread unsafe.
# File lib/util/schedule.rb, line 35 def initialize() @entries = []; end
# File lib/util/schedule.rb, line 61 def clear() @entries.clear; end
# File lib/util/schedule.rb, line 37 def empty?() @entries.empty?; end
@param at [Time] Insert item at time at
@param at [Numeric]
Insert item at +Time.now + at+ @param at [0] Insert item at Time.at(0)
# File lib/util/schedule.rb, line 46 def insert(at, item) time = case at when 0 then Time.at(0) # Avoid call to Time.now for immediate tasks when Numeric then Time.now + at else at end index = time && ((0...@entries.size).bsearch { |i| @entries[i].time > time }) @entries.insert(index || -1, Entry.new(time, item)) end
# File lib/util/schedule.rb, line 39 def next_tick() @entries.first.time unless @entries.empty? end
Return next item due at or before time, else nil
# File lib/util/schedule.rb, line 57 def pop(time) @entries.shift.item if !@entries.empty? && before_eq(@entries.first.time, time) end