Module: Empathy::EM::Kernel
- Defined in:
- lib/empathy/em/thread.rb
Class Method Summary collapse
-
.at_exit(&block) ⇒ void
Like ::Kernel.at_exit.
-
.sleep(seconds = :__empathy_sleep_forever) ⇒ Fixnum
Like ::Kernel.sleep.
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 |
.sleep ⇒ Fixnum .sleep(seconds) ⇒ Fixnum
Like ::Kernel.sleep
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 |