lib/trailblazer/circuit.rb in trailblazer-activity-0.5.1 vs lib/trailblazer/circuit.rb in trailblazer-activity-0.5.2
- old
+ new
@@ -9,10 +9,12 @@
#
# result = circuit.(start_at, *args)
#
# @see Activity
# @api semi-private
+ #
+ # This is the "pipeline operator"'s implementation.
class Circuit
def initialize(map, stop_events, name: nil, start_task: map.keys.first)
@map = map
@stop_events = stop_events
@name = name
@@ -31,24 +33,26 @@
# @param task An event or task of this circuit from where to start
# @param options anything you want to pass to the first task
# @param flow_options Library-specific flow control data
# @return [last_signal, options, flow_options, *args]
#
- # DISCUSS: returned circuit_options are ignored when calling the runner.
+ # NOTE: returned circuit_options are discarded when calling the runner.
def call(args, task: @start_task, runner: Run, **circuit_options)
+ circuit_options = circuit_options.merge( runner: runner ).freeze # TODO: set the :runner option via arguments_for_call to save the merge?
+
loop do
- last_signal, args, _ignored_circuit_options = runner.(
+ last_signal, args, _discarded_circuit_options = runner.(
task,
args,
- circuit_options.merge( runner: runner ) # options for runner, to be discarded.
+ circuit_options
)
# Stop execution of the circuit when we hit a stop event (< End). This could be an task's End or Suspend.
return [ last_signal, args ] if @stop_events.include?(task) # DISCUSS: return circuit_options here?
task = next_for(task, last_signal) do |next_task, in_map|
raise IllegalInputError.new("#{task}") unless in_map
- raise IllegalOutputSignalError.new("#{@name}[#{task}][ #{last_signal.inspect} ]") unless next_task
+ raise IllegalOutputSignalError.new("<#{@name}>[#{task}][ #{last_signal.inspect} ]") unless next_task
end
end
end
# Returns the circuit's components.