module EM::Wrapper
Wraps objects callbacks to EventMachine next ticks, so multiplexes them.
Public Class Methods
new(cls)
click to toggle source
Creates new wrapper.
@param [Object, Class] cls wrapped object or class @return [Object, Class] another object or class of the same class linked to original object
# File lib/em-wrapper.rb, line 28 def self.new(cls) op = OP::catch(cls) worker = Proc::new do |object| object.method_call do |name, args, block| object.wrapped.send(name, *args) do |result| if not block.nil? EM::next_tick do result = [result] if not result.kind_of? Array block.call(*result) end end end end end if cls.kind_of? Class op.instance_created do |object| worker.call(object) end else worker.call(op) end return op end