class Qpid::Proton::Schedule

@private A time-sorted list of objects. Thread unsafe.

Constants

Entry

Public Class Methods

new() click to toggle source
# File lib/util/schedule.rb, line 35
def initialize() @entries = []; end

Public Instance Methods

clear() click to toggle source
# File lib/util/schedule.rb, line 61
def clear() @entries.clear; end
empty?() click to toggle source
# File lib/util/schedule.rb, line 37
def empty?() @entries.empty?; end
insert(at, item) click to toggle source

@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
next_tick() click to toggle source
# File lib/util/schedule.rb, line 39
def next_tick()
  @entries.first.time unless @entries.empty?
end
pop(time) click to toggle source

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