module Empathy::EM::Kernel

Public Class Methods

at_exit(&block) click to toggle source

Like ::Kernel.at_exit

Queues block to run at shutdown of the reactor @return [void]

# File lib/empathy/em/thread.rb, line 50
def self.at_exit(&block)
  EventMachine.add_shutdown_hook(&block)
end
sleep(seconds=:__empathy_sleep_forever) click to toggle source

Like ::Kernel.sleep @overload sleep()

Sleep forever

@overload sleep(seconds)

@param [Numeric] seconds The number of seconds (including fractional seconds) to sleep

@return [Fixnum] rounded number of seconds actually slept, which can be less than specified if woken early

# File lib/empathy/em/thread.rb, line 34
def self.sleep(seconds=:__empathy_sleep_forever)

  ::Kernel.raise TypeError, "seconds #{seconds} must be a number" unless seconds == :__empathy_sleep_forever or seconds.is_a? Numeric
  n = Time.now

  em_thread = Thread.current
  timer = ::EM::Timer.new(seconds){ em_thread.__send__(:wake_resume) } unless seconds == :__empathy_sleep_forever
  em_thread.__send__(:yield_sleep,timer)

  (Time.now - n).round()
end