class Concurrent::Actor::Behaviour::SetResults

Collects returning value and sets the CompletableFuture in the {Envelope} or error on failure.

Attributes

error_strategy[R]

Public Class Methods

new(core, subsequent, core_options, error_strategy) click to toggle source
# File lib/concurrent/actor/behaviour/sets_results.rb, line 8
def initialize(core, subsequent, core_options, error_strategy)
  super core, subsequent, core_options
  @error_strategy = Match! error_strategy, :just_log, :terminate!, :pause!
end

Public Instance Methods

on_envelope(envelope) click to toggle source
# File lib/concurrent/actor/behaviour/sets_results.rb, line 13
def on_envelope(envelope)
  result = pass envelope
  if result != MESSAGE_PROCESSED && !envelope.future.nil?
    envelope.future.success result
    log(DEBUG) { "finished processing of #{envelope.message.inspect}"}
  end
  nil
rescue => error
  log ERROR, error
  case error_strategy
  when :terminate!
    terminate!
  when :pause!
    behaviour!(Pausing).pause!(error)
  when :just_log
    # nothing
  else
    raise
  end
  envelope.future.fail error unless envelope.future.nil?
end