Class: Concurrent::Actor::Behaviour::SetResults

Inherits:
Abstract
  • Object
show all
Defined in:
lib/concurrent/actor/behaviour/sets_results.rb

Overview

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

Instance Attribute Summary collapse

Attributes inherited from Abstract

#core, #subsequent

Instance Method Summary collapse

Methods inherited from Abstract

#broadcast, #on_event, #pass, #reject_envelope

Methods included from InternalDelegations

#behaviour, #behaviour!, #children, #context, #dead_letter_routing, #log, #redirect, #terminate!, #terminated?

Methods included from PublicDelegations

#context_class, #executor, #name, #parent, #path, #reference

Methods included from TypeCheck

#Child!, #Child?, #Match!, #Match?, #Type!, #Type?

Constructor Details

#initialize(core, subsequent, core_options, error_strategy) ⇒ SetResults

Returns a new instance of SetResults.



8
9
10
11
# 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

Instance Attribute Details

#error_strategyObject (readonly)



6
7
8
# File 'lib/concurrent/actor/behaviour/sets_results.rb', line 6

def error_strategy
  @error_strategy
end

Instance Method Details

#on_envelope(envelope) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# 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