class BiteTheDust::BiteTheDust

Public Class Methods

new(time) click to toggle source
# File lib/bite_the_dust.rb, line 22
def initialize(time)
  @now = Time.now
  @time = time
end

Public Instance Methods

future?() click to toggle source
# File lib/bite_the_dust.rb, line 27
def future?
  @now < @time
end
set_timer(&block) click to toggle source
# File lib/bite_the_dust.rb, line 31
def set_timer(&block)
  if future? then
    begin
      num_of_seconds = @time - Time.now
      EM.run do
        EM.add_timer(num_of_seconds.to_i) do
          EM.stop_event_loop              
          return block.call
        end
      end
    rescue RangeError
      raise RangeError, "Time too far"
    end
  else
    return block.call
  end
end