Class: Helpstation::Processors::ParallelProcessor

Inherits:
Helpstation::Processor show all
Defined in:
lib/helpstation/processors.rb

Overview

Helps to run processors in parallel

All output from the processors are merged and then returned. This means that if two fetchers return results with the same key then one will overwrite the other.

Examples:

process ParallelProcessor[
  OperatorFetcher,
  VisitorFetcher
], NOT_FOUND_ERROR

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Helpstation::Processor

#success

Methods inherited from Evaluator

call

Constructor Details

#initialize(processors) ⇒ ParallelProcessor

Returns a new instance of ParallelProcessor.



20
21
22
# File 'lib/helpstation/processors.rb', line 20

def initialize(processors)
  @processors = processors
end

Class Method Details

.[](*processors) ⇒ Object



16
17
18
# File 'lib/helpstation/processors.rb', line 16

def self.[](*processors)
  new(processors)
end

Instance Method Details

#call(request) ⇒ Object



24
25
26
27
28
29
30
31
32
# File 'lib/helpstation/processors.rb', line 24

def call(request)
  results = process_parallel(request)

  if first_failure = results.detect {|result| !result.success?}
    first_failure
  else
    request.success(results.reduce(request.input, &method(:compose)))
  end
end