Class: AWS::Flow::Core::Task Private

Inherits:
FlowFiber
  • Object
show all
Defined in:
lib/aws/flow/tasks.rb

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Direct Known Subclasses

DaemonTask

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from FlowFiber

#[], [], []=, #[]=, finalize, unset

Constructor Details

#initialize(__context__, &block) ⇒ Task

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Creates a new task.

Parameters:

  • __context__

    A task needs a reference to the __context__ that created it so that when the “task” macro is called it can find the __context__, which the new task should be added to.

  • block

    A block of code that will be run by the task.



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
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/aws/flow/tasks.rb', line 36

def initialize(__context__, &block)
  @__context__ = __context__
  @result = Future.new
  @block = block

  # Is the task alive?
  #
  # @return Boolean
  #   true if the task is alive and has not been canceled.
  #
  # @api private
  def alive?
    super && !@cancelled
    #!!@alive# && !@cancelled
  end

  # Retrieves the executor for this task.
  #
  # @return
  #   The executor for this task.
  #
  # @api private
  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

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



24
25
26
# File 'lib/aws/flow/tasks.rb', line 24

def __context__
  @__context__
end

#backtraceObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



24
25
26
# File 'lib/aws/flow/tasks.rb', line 24

def backtrace
  @backtrace
end

#blockObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



23
24
25
# File 'lib/aws/flow/tasks.rb', line 23

def block
  @block
end

#parentObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



24
25
26
# File 'lib/aws/flow/tasks.rb', line 24

def parent
  @parent
end

#resultObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



23
24
25
# File 'lib/aws/flow/tasks.rb', line 23

def result
  @result
end

Instance Method Details

#<<(this_task) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Adds a task to this task’s context.

Parameters:

  • this_task

    The task to add.



137
138
139
# File 'lib/aws/flow/tasks.rb', line 137

def <<(this_task)
  @__context__.parent << this_task
end

#alive?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Is the task alive?

Returns:

  • (Boolean)

    Boolean true if the task is alive and has not been canceled.



47
48
49
50
# File 'lib/aws/flow/tasks.rb', line 47

def alive?
  super && !@cancelled
  #!!@alive# && !@cancelled
end

#cancel(error) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Prevents the execution of this particular task, if possible.

Parameters:

  • error

    The error that is the cause of the cancellation.



113
114
115
116
# File 'lib/aws/flow/tasks.rb', line 113

def cancel(error)
  @cancelled = true
  @__context__.remove(self)
end

#executorObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Retrieves the executor for this task.

Returns:

  • The executor for this task.



58
59
60
# File 'lib/aws/flow/tasks.rb', line 58

def executor
  @__context__.executor
end

#fail(this_task, error) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Fails the given task with the specified error.

Parameters:

  • error

    The error that is the cause of the failure.



124
125
126
# File 'lib/aws/flow/tasks.rb', line 124

def fail(this_task, error)
  @__context__.fail(this_task, error)
end

#get_heirsObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Passes all ‘get_heirs` calls to the class that is holding the context, to ensure uniform handling of `get_heirs`.



86
87
88
# File 'lib/aws/flow/tasks.rb', line 86

def get_heirs
  @__context__.get_heirs
end

#is_daemon?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Will always be false. Provides a common API for BeginRescueEnsure to ensure they are maintaining their nonDaemonHeirsCount correctly.

Returns:

  • (Boolean)


94
95
96
# File 'lib/aws/flow/tasks.rb', line 94

def is_daemon?
  return false
end

#remove(this_task) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Removes a task from this task’s context.

Parameters:

  • this_task

    The task to remove.



147
148
149
# File 'lib/aws/flow/tasks.rb', line 147

def remove(this_task)
  @__context__.remove(this_task)
end

#scheduleObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

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.



103
104
105
# File 'lib/aws/flow/tasks.rb', line 103

def schedule
  @__context__ << self
end