Class: AWS::Flow::Core::Task
- Defined in:
- lib/aws/flow/tasks.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#__context__ ⇒ Object
Returns the value of attribute __context__.
-
#backtrace ⇒ Object
Returns the value of attribute backtrace.
-
#block ⇒ Object
readonly
Returns the value of attribute block.
-
#parent ⇒ Object
Returns the value of attribute parent.
-
#result ⇒ Object
readonly
Returns the value of attribute result.
Instance Method Summary collapse
-
#<<(this_task) ⇒ Object
Adds a task to this task’s context.
-
#alive? ⇒ Boolean
Is the task alive?.
-
#cancel(error) ⇒ Object
Cancel will prevent the execution of this particular task, if possible.
-
#executor ⇒ Object
The executor for this task.
-
#get_heirs ⇒ Object
Passes the get_heirs calls to the context, to ensure uniform handling of get_heirs.
-
#initialize(__context__, &block) ⇒ Task
constructor
Creates a new Task.
-
#is_daemon? ⇒ Boolean
Returns true/false, depending on if we are in a daemon task or not.
-
#remove(this_task) ⇒ Object
Removes a task from this task’s context.
-
#schedule ⇒ Object
Used by Future#signal to schedule the task for re-evaluation.
Methods inherited from FlowFiber
#[], [], []=, #[]=, finalize, unset
Constructor Details
#initialize(__context__, &block) ⇒ Task
Creates a new Task.
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/aws/flow/tasks.rb', line 34 def initialize(__context__, &block) @__context__ = __context__ @result = Future.new @block = block # Is the task alive? def alive? super && !@cancelled #!!@alive# && !@cancelled end # @return # The executor for this task. def executor @__context__.executor end super() do begin # Not return because 1.9 will freak about local jump problems if you # try to return, as this is inside a block next if @cancelled @result.set(lambda(&block).call) next if @cancelled @__context__.remove(self) rescue Exception => e if @backtrace != e backtrace = AsyncBacktrace.create_from_exception(@backtrace, e) e.set_backtrace(backtrace.backtrace) if backtrace end @__context__.fail(self, e) ensure end end end |
Instance Attribute Details
#__context__ ⇒ Object
Returns the value of attribute __context__.
23 24 25 |
# File 'lib/aws/flow/tasks.rb', line 23 def __context__ @__context__ end |
#backtrace ⇒ Object
Returns the value of attribute backtrace.
23 24 25 |
# File 'lib/aws/flow/tasks.rb', line 23 def backtrace @backtrace end |
#block ⇒ Object (readonly)
Returns the value of attribute block.
22 23 24 |
# File 'lib/aws/flow/tasks.rb', line 22 def block @block end |
#parent ⇒ Object
Returns the value of attribute parent.
23 24 25 |
# File 'lib/aws/flow/tasks.rb', line 23 def parent @parent end |
#result ⇒ Object (readonly)
Returns the value of attribute result.
22 23 24 |
# File 'lib/aws/flow/tasks.rb', line 22 def result @result end |
Instance Method Details
#<<(this_task) ⇒ Object
Adds a task to this task’s context
120 121 122 |
# File 'lib/aws/flow/tasks.rb', line 120 def <<(this_task) @__context__.parent << this_task end |
#alive? ⇒ Boolean
Is the task alive?
40 41 42 43 |
# File 'lib/aws/flow/tasks.rb', line 40 def alive? super && !@cancelled #!!@alive# && !@cancelled end |
#cancel(error) ⇒ Object
Cancel will prevent the execution of this particular task, if possible
97 98 99 100 |
# File 'lib/aws/flow/tasks.rb', line 97 def cancel(error) @cancelled = true @__context__.remove(self) end |
#executor ⇒ Object
Returns The executor for this task.
47 48 49 |
# File 'lib/aws/flow/tasks.rb', line 47 def executor @__context__.executor end |
#get_heirs ⇒ Object
Passes the get_heirs calls to the context, to ensure uniform handling of get_heirs
73 74 75 |
# File 'lib/aws/flow/tasks.rb', line 73 def get_heirs @__context__.get_heirs end |
#is_daemon? ⇒ Boolean
Returns true/false, depending on if we are in a daemon task or not
80 81 82 |
# File 'lib/aws/flow/tasks.rb', line 80 def is_daemon? return false end |
#remove(this_task) ⇒ Object
Removes a task from this task’s context
129 130 131 |
# File 'lib/aws/flow/tasks.rb', line 129 def remove(this_task) @__context__.remove(this_task) end |
#schedule ⇒ Object
Used by Future#signal to schedule the task for re-evaluation.
This will simply add the task back to the list of things to be run in the parent’s event loop.
88 89 90 |
# File 'lib/aws/flow/tasks.rb', line 88 def schedule @__context__ << self end |