Module: EM::Wrapper
- Defined in:
- lib/em-wrapper.rb
Overview
Wraps objects callbacks to EventMachine next ticks, so multiplexes them.
Class Method Summary collapse
-
.new(cls) ⇒ Object, Class
Creates new wrapper.
Class Method Details
.new(cls) ⇒ Object, Class
Creates new wrapper.
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# 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 |