Module: Kernel

Defined in:
lib/em-synchrony/kernel.rb,
lib/em-synchrony/core_ext.rb

Overview

Monkey-patch

Class Attribute Summary collapse

Instance Method Summary collapse

Class Attribute Details

.em_synchrony_sleep_hookObject

Returns the value of attribute em_synchrony_sleep_hook


9
10
11
# File 'lib/em-synchrony/kernel.rb', line 9

def em_synchrony_sleep_hook
  @em_synchrony_sleep_hook
end

Instance Method Details

#orig_sleepObject


6
# File 'lib/em-synchrony/kernel.rb', line 6

alias_method :orig_sleep, :sleep

#silence_warningsObject


3
4
5
6
7
8
# File 'lib/em-synchrony/core_ext.rb', line 3

def silence_warnings
  old_verbose, $VERBOSE = $VERBOSE, nil
  yield
ensure
  $VERBOSE = old_verbose
end

#sleep(*args) ⇒ Object

Monkey-patch


13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/em-synchrony/kernel.rb', line 13

def sleep(*args)
  if Kernel.em_synchrony_sleep_hook &&
     EM.reactor_thread? &&
     !Thread.current[:em_synchrony_sleep_hook_called]
    begin
      Thread.current[:em_synchrony_sleep_hook_called] = true
      Kernel.em_synchrony_sleep_hook.call(args[0])
    ensure
      Thread.current[:em_synchrony_sleep_hook_called] = false
    end
  else
    orig_sleep(*args)
  end
end