Module: Empathy::EM::Kernel

Defined in:
lib/empathy/em/thread.rb

Class Method Summary collapse

Class Method Details

.at_exit(&block) ⇒ void

This method returns an undefined value.

Like ::Kernel.at_exit

Queues block to run at shutdown of the reactor



50
51
52
# File 'lib/empathy/em/thread.rb', line 50

def self.at_exit(&block)
  EventMachine.add_shutdown_hook(&block)
end

.sleepFixnum .sleep(seconds) ⇒ Fixnum

Like ::Kernel.sleep

Overloads:

  • .sleepFixnum

    Sleep forever

  • .sleep(seconds) ⇒ Fixnum

    Parameters:

    • seconds (Numeric)

      The number of seconds (including fractional seconds) to sleep

Returns:

  • (Fixnum)

    rounded number of seconds actually slept, which can be less than specified if woken early



34
35
36
37
38
39
40
41
42
43
44
# 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