lib/em-synchrony.rb in em-synchrony-1.0.4 vs lib/em-synchrony.rb in em-synchrony-1.0.5
- old
+ new
@@ -13,10 +13,11 @@
require "em-synchrony/em-multi"
require "em-synchrony/tcpsocket"
require "em-synchrony/connection_pool"
require "em-synchrony/keyboard"
require "em-synchrony/iterator" if EventMachine::VERSION > '0.12.10'
+require "em-synchrony/kernel"
module EventMachine
# A convenience method for wrapping a given block within
# a Ruby Fiber such that async operations can be transparently
@@ -128,10 +129,19 @@
fiber = Fiber.current
EM.system(cmd, *args){ |out, status| fiber.resume( [out, status] ) }
Fiber.yield
end
+ # Overrides behavior of kernel.sleep
+ # Allows to add custom behavior, e.g. logging or redirection to
+ # EM::Synchrony.sleep .
+ # Calling 'sleep' in this function calls the actual kernel method.
+ #
+ def self.on_sleep(&blk)
+ Kernel.em_synchrony_sleep_hook = blk
+ end
+
# Routes to EM::Synchrony::Keyboard
#
def self.gets
EventMachine::Synchrony::Keyboard.new.gets
end
@@ -143,5 +153,8 @@
EM.next_tick { fiber.resume }
Fiber.yield
end
end
end
+
+# Alias for {EventMachine::Synchrony}
+EM::S = EventMachine::Synchrony
\ No newline at end of file