Class: CDC::Concurrent::ResultCollector

Inherits:
Object
  • Object
show all
Defined in:
lib/cdc/concurrent/result_collector.rb

Overview

Normalizes values returned by Async tasks into ProcessorResult objects.

ResultCollector keeps runtime pools tolerant of processors that either return a CDC::Core::ProcessorResult directly or return a plain Ruby value. Plain values are wrapped as successful ProcessorResult instances, while raised errors are represented as failure results.

Class Method Summary collapse

Class Method Details

.failure(error) ⇒ CDC::Core::ProcessorResult

Wraps an exception as a failed ProcessorResult.

Parameters:

  • error (Exception)

    Error raised while processing an event.

Returns:

  • (CDC::Core::ProcessorResult)

    Failure result containing the supplied error.



28
29
30
# File 'lib/cdc/concurrent/result_collector.rb', line 28

def self.failure(error)
  CDC::Core::ProcessorResult.failure(error)
end

.normalize(value) ⇒ CDC::Core::ProcessorResult

Normalizes a processor return value into a ProcessorResult.

Parameters:

  • value (Object)

    Value returned by a processor or an existing ProcessorResult.

Returns:

  • (CDC::Core::ProcessorResult)

    Existing ProcessorResult or success result wrapping the value.



16
17
18
19
20
21
22
# File 'lib/cdc/concurrent/result_collector.rb', line 16

def self.normalize(value)
  return value if value.is_a?(CDC::Core::ProcessorResult)

  CDC::Core::ProcessorResult.success(value)
rescue StandardError => e
  failure(e)
end