Class: AWS::Flow::Core::BeginRescueEnsure
- Extended by:
- SimpleDFA
- Defined in:
- lib/aws/flow/begin_rescue_ensure.rb
Overview
Direct Known Subclasses
Instance Attribute Summary collapse
-
#__context__ ⇒ Object
readonly
Returns the value of attribute __context__.
-
#backtrace ⇒ Object
readonly
Returns the value of attribute backtrace.
-
#begin_task ⇒ Object
Returns the value of attribute begin_task.
-
#cancelled ⇒ Object
Returns the value of attribute cancelled.
-
#ensure_task ⇒ Object
Returns the value of attribute ensure_task.
-
#executor ⇒ Object
Returns the value of attribute executor.
-
#failure ⇒ Object
Returns the value of attribute failure.
-
#heirs ⇒ Object
Returns the value of attribute heirs.
-
#nonDaemonHeirsCount ⇒ Object
Returns the value of attribute nonDaemonHeirsCount.
-
#parent ⇒ Object
Returns the value of attribute parent.
-
#rescue_exceptions ⇒ Object
Returns the value of attribute rescue_exceptions.
-
#rescue_tasks ⇒ Object
Returns the value of attribute rescue_tasks.
-
#result ⇒ Object
Returns the value of attribute result.
Attributes included from SimpleDFA
#start_state, #states, #symbols, #transitions
Instance Method Summary collapse
-
#begin(block) ⇒ Object
Binds the block to the a lambda to be called when we get to the begin part of the DFA.
-
#ensure(block) ⇒ Object
Binds the block to the a lambda to be called when we get to the ensure part of the DFA.
-
#fail(this_task, error) ⇒ Object
Fails the task, cancels all of its heirs, and then updates the state.
-
#initialize(options = {}) ⇒ BeginRescueEnsure
constructor
Create a new BeginRescueEnsure object, with the provided options.
-
#remove(this_task) ⇒ Object
Removes the task and updates the state.
-
#rescue(error_type, block) ⇒ Object
Binds the block to the a lambda to be called when we get to the rescue part of the DFA.
- #schedule ⇒ Object
Methods included from SimpleDFA
add_transition, define_general, get_start_state, get_transitions, init, uncovered_transitions
Methods inherited from FlowFiber
#[], [], []=, #[]=, finalize, unset
Constructor Details
#initialize(options = {}) ⇒ BeginRescueEnsure
Create a new BeginRescueEnsure object, with the provided options.
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/aws/flow/begin_rescue_ensure.rb', line 40 def initialize( = {}) # We have two different arrays, rather than a hash, # because we want to ensure that we process the rescues in the order # they are written, and because prior to Ruby 1.9, hashes will not # return their elements in the order they were inserted. @rescue_exceptions = [] @rescue_tasks = [] @parent = [:parent] || Fiber.current.__context__ @current = @parent @executor = @parent.executor @__context__ = self @nonDaemonHeirsCount = 0 @current_state ||= self.class.get_start_state @heirs = Set.new @backtrace = make_backtrace(@parent.backtrace) @result = Future.new super() { consume(:run) } end |
Instance Attribute Details
#__context__ ⇒ Object (readonly)
Returns the value of attribute __context__.
30 31 32 |
# File 'lib/aws/flow/begin_rescue_ensure.rb', line 30 def __context__ @__context__ end |
#backtrace ⇒ Object (readonly)
Returns the value of attribute backtrace.
30 31 32 |
# File 'lib/aws/flow/begin_rescue_ensure.rb', line 30 def backtrace @backtrace end |
#begin_task ⇒ Object
Returns the value of attribute begin_task.
28 29 30 |
# File 'lib/aws/flow/begin_rescue_ensure.rb', line 28 def begin_task @begin_task end |
#cancelled ⇒ Object
Returns the value of attribute cancelled.
28 29 30 |
# File 'lib/aws/flow/begin_rescue_ensure.rb', line 28 def cancelled @cancelled end |
#ensure_task ⇒ Object
Returns the value of attribute ensure_task.
28 29 30 |
# File 'lib/aws/flow/begin_rescue_ensure.rb', line 28 def ensure_task @ensure_task end |
#executor ⇒ Object
Returns the value of attribute executor.
28 29 30 |
# File 'lib/aws/flow/begin_rescue_ensure.rb', line 28 def executor @executor end |
#failure ⇒ Object
Returns the value of attribute failure.
28 29 30 |
# File 'lib/aws/flow/begin_rescue_ensure.rb', line 28 def failure @failure end |
#heirs ⇒ Object
Returns the value of attribute heirs.
28 29 30 |
# File 'lib/aws/flow/begin_rescue_ensure.rb', line 28 def heirs @heirs end |
#nonDaemonHeirsCount ⇒ Object
Returns the value of attribute nonDaemonHeirsCount.
28 29 30 |
# File 'lib/aws/flow/begin_rescue_ensure.rb', line 28 def nonDaemonHeirsCount @nonDaemonHeirsCount end |
#parent ⇒ Object
Returns the value of attribute parent.
28 29 30 |
# File 'lib/aws/flow/begin_rescue_ensure.rb', line 28 def parent @parent end |
#rescue_exceptions ⇒ Object
Returns the value of attribute rescue_exceptions.
28 29 30 |
# File 'lib/aws/flow/begin_rescue_ensure.rb', line 28 def rescue_exceptions @rescue_exceptions end |
#rescue_tasks ⇒ Object
Returns the value of attribute rescue_tasks.
28 29 30 |
# File 'lib/aws/flow/begin_rescue_ensure.rb', line 28 def rescue_tasks @rescue_tasks end |
#result ⇒ Object
Returns the value of attribute result.
28 29 30 |
# File 'lib/aws/flow/begin_rescue_ensure.rb', line 28 def result @result end |
Instance Method Details
#begin(block) ⇒ Object
Binds the block to the a lambda to be called when we get to the begin part of the DFA
265 266 267 268 269 |
# File 'lib/aws/flow/begin_rescue_ensure.rb', line 265 def begin(block) raise "Duplicated begin" if @begin_task # @begin_task = lambda { block.call } @begin_task = Task.new(self) { @result.set(block.call) } end |
#ensure(block) ⇒ Object
Binds the block to the a lambda to be called when we get to the ensure part of the DFA
293 294 295 296 |
# File 'lib/aws/flow/begin_rescue_ensure.rb', line 293 def ensure(block) raise "Duplicated ensure" if @ensure_task @ensure_task = Task.new(self) { block.call } end |
#fail(this_task, error) ⇒ Object
Fails the task, cancels all of its heirs, and then updates the state.
103 104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/aws/flow/begin_rescue_ensure.rb', line 103 def fail(this_task, error) check_closed if ( ! (error.class <= CancellationException) || @failure == nil && !@daemondCausedCancellation) backtrace = AsyncBacktrace.create_from_exception(@backtrace, error) error.set_backtrace(backtrace.backtrace) if backtrace @failure = error end task_out = @heirs.delete?(this_task) raise "There was a task attempted to be removed from a BRE, when the BRE did not have that task as an heir" unless task_out @nonDaemonHeirsCount -= 1 if ! this_task.is_daemon? cancelHeirs update_state end |
#remove(this_task) ⇒ Object
Removes the task and updates the state
122 123 124 125 126 127 128 129 |
# File 'lib/aws/flow/begin_rescue_ensure.rb', line 122 def remove(this_task) check_closed task_out = @heirs.delete?(this_task) raise "There was a task attempted to be removed from a BRE, when the BRE did not have that task as an heir" unless task_out @nonDaemonHeirsCount -= 1 if ! this_task.is_daemon? update_state end |
#rescue(error_type, block) ⇒ Object
Binds the block to the a lambda to be called when we get to the rescue part of the DFA
279 280 281 282 283 284 285 286 |
# File 'lib/aws/flow/begin_rescue_ensure.rb', line 279 def rescue(error_type, block) this_task = lambda { |failure| block.call(failure) } if @rescue_exceptions.include? error_type raise "You have already registered #{error_type}!" end @rescue_exceptions << error_type @rescue_tasks << this_task end |
#schedule ⇒ Object
298 299 300 |
# File 'lib/aws/flow/begin_rescue_ensure.rb', line 298 def schedule @parent << self end |