Class: Kanal::Core::Helpers::ResponseExecutionBlock

Inherits:
Object
  • Object
show all
Includes:
Logging::Logger, Output
Defined in:
lib/kanal/core/helpers/response_execution_block.rb

Overview

This class executes response block and constructs output It is also can execute response block and disable moving it forward to the queue

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Logging::Logger

#logger

Constructor Details

#initialize(response_block, input, default_error_node, error_node) ⇒ ResponseExecutionBlock

Creating response execution block with all needed parameters

Parameters:



29
30
31
32
33
34
# File 'lib/kanal/core/helpers/response_execution_block.rb', line 29

def initialize(response_block, input, default_error_node, error_node)
  @response_block = response_block
  @input = input
  @default_error_node = default_error_node
  @error_node = error_node
end

Instance Attribute Details

#inputObject (readonly)

Returns the value of attribute input.



19
20
21
# File 'lib/kanal/core/helpers/response_execution_block.rb', line 19

def input
  @input
end

#response_blockObject (readonly)

Returns the value of attribute response_block.



19
20
21
# File 'lib/kanal/core/helpers/response_execution_block.rb', line 19

def response_block
  @response_block
end

Instance Method Details

#execute(core, input_output_pair_queue) ⇒ void

This method returns an undefined value.

Execute response block and ship created output into the queue

Parameters:

  • core (Kanal::Core::Core)

    core to access parameter registrators and stuff TODO: remove core here and provide registrator as dependency

  • input_output_pair_queue (Kanal::Core::Helpers::Queue)

    queue where Kanal::Core::Helpers::InputOutputPair will be stored



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/kanal/core/helpers/response_execution_block.rb', line 44

def execute(core, input_output_pair_queue)
  if response_block.async?
    # NOTE: Thread doesnt just die here - it's execution is continued in input_output_pair_queue.enqueue in router
    # then :item_queued hook is called inside and subsequently output_ready_block gets called in this thread
    # TODO: be aware that this can cause unexpected behaviour. Maybe think how to rework it.
    Thread.new do
      output = construct_output core
      unless output.canceled?
        input_output_pair_queue.enqueue InputOutputPair.new(@input, output)
      end
    end
  else
    output = construct_output core
    unless output.canceled?
      input_output_pair_queue.enqueue InputOutputPair.new(@input, output)
    end
  end
end