Class: Noder::Events::EMEventNode

Inherits:
Object
  • Object
show all
Defined in:
lib/noder/events/em_event_node.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ EMEventNode

Returns a new instance of EMEventNode.



6
7
8
9
10
# File 'lib/noder/events/em_event_node.rb', line 6

def initialize(options={})
  @callback = options[:callback]
  @argument_keys = options[:argument_keys]
  raise 'No callback provided' if @callback.nil?
end

Instance Attribute Details

#callbackObject

Returns the value of attribute callback.



4
5
6
# File 'lib/noder/events/em_event_node.rb', line 4

def callback
  @callback
end

#next_nodeObject

Returns the value of attribute next_node.



4
5
6
# File 'lib/noder/events/em_event_node.rb', line 4

def next_node
  @next_node
end

Instance Method Details

#call(env) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/noder/events/em_event_node.rb', line 12

def call(env)
  if callback.respond_to?(:matches_env?) && !callback.matches_env?(env)
    if next_node
      operation = proc { next_node.call(env) }
      EM.defer(operation)
    end
    return
  end
  operation = proc { call_operation(env) }
  if next_node
    callback = proc { |env| next_node.call(env) }
    EM.defer(operation, callback)
  else
    EM.defer(operation)
  end
  env
end