Module: AWS::Flow::Core
- Defined in:
- lib/aws/flow/fiber.rb,
lib/aws/flow/tasks.rb,
lib/aws/flow/future.rb,
lib/aws/flow/flow_utils.rb,
lib/aws/flow/simple_dfa.rb,
lib/aws/flow/async_scope.rb,
lib/aws/flow/implementation.rb,
lib/aws/flow/async_backtrace.rb,
lib/aws/flow/begin_rescue_ensure.rb
Defined Under Namespace
Modules: SimpleDFA Classes: AlreadySetException, BeginRescueEnsure, BeginRescueEnsureWrapper, CancellationException, DaemonBeginRescueEnsure, DaemonTask, ExternalTask, FiberConditionVariable, FlowFiber, Future, IllegalStateException, NoContextException, Task
Instance Method Summary collapse
-
#daemon_task(&block) ⇒ Future
The tasks result, which is a Future.
-
#error_handler(&block) ⇒ Object
-
Args : - block -> a block, which is passed in a BeginRescueEnsureWrapper, and which will define the BeginRescueEnsure#begin, BeginRescueEnsure#rescue, and BeginRescueEnsure#ensure methods * Returns : - The result of the begin statement, if there is no error, otherwise the value of the return statement * Raises : -
NoContextException
-> If the current fiber does not respond to #__context__.
-
- #external_task(&block) ⇒ nil
- #gate_by_version(version, method, &block) ⇒ Object
- #make_backtrace(parent_backtrace) ⇒ Object
-
#task(future = nil, &block) ⇒ Future
The tasks result, which is a Future.
-
#wait_for_all(*futures) ⇒ Array
Blocks until all of the arguments are set.
-
#wait_for_any(*futures) ⇒ Array
Blocks until any of the arguments are set.
- #wait_for_function(function, *futures) ⇒ Object
Instance Method Details
#daemon_task(&block) ⇒ Future
Returns The tasks result, which is a Future.
51 52 53 54 55 56 57 58 59 |
# File 'lib/aws/flow/implementation.rb', line 51 def daemon_task(&block) fiber = ::Fiber.current raise NoContextException unless fiber.respond_to? :__context__ context = fiber.__context__ t = DaemonTask.new(nil, &block) task_context = TaskContext.new(:parent => context.get_closest_containing_scope, :task => t) context << t t.result end |
#error_handler(&block) ⇒ Object
-
Args :
-
block -> a block, which is passed in a BeginRescueEnsureWrapper, and which will define the BeginRescueEnsure#begin, BeginRescueEnsure#rescue, and BeginRescueEnsure#ensure methods
-
-
Returns :
-
The result of the begin statement, if there is no error, otherwise the value of the return statement
-
-
Raises :
-
NoContextException
-> If the current fiber does not respond to #__context__
-
90 91 92 93 94 95 96 97 98 99 |
# File 'lib/aws/flow/implementation.rb', line 90 def error_handler(&block) fiber = ::Fiber.current raise NoContextException unless fiber.respond_to? :__context__ context = fiber.__context__ begin_rescue_ensure = BeginRescueEnsure.new(:parent => context.get_closest_containing_scope) bge = BeginRescueEnsureWrapper.new(block, begin_rescue_ensure) context << bge context << begin_rescue_ensure begin_rescue_ensure end |
#external_task(&block) ⇒ nil
70 71 72 73 74 75 76 77 78 |
# File 'lib/aws/flow/implementation.rb', line 70 def external_task(&block) fiber = ::Fiber.current raise NoContextException unless fiber.respond_to? :__context__ context = fiber.__context__ t = ExternalTask.new(:parent => context.get_closest_containing_scope, &block) task_context = TaskContext.new(:parent => context.get_closest_containing_scope, :task => t) context << t nil end |
#gate_by_version(version, method, &block) ⇒ Object
22 23 24 25 26 |
# File 'lib/aws/flow/async_scope.rb', line 22 def gate_by_version(version, method, &block) if RUBY_VERSION.send(method, version) block.call end end |
#make_backtrace(parent_backtrace) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/aws/flow/flow_utils.rb', line 29 def make_backtrace(parent_backtrace) # 1 frame for the function that actually removes the stack traces # 1 frame for the function that calls into the function that removes # frames in AsyncBacktrace # 1 frame for the call into this function # 1 frame for the initialize call of the BRE or External Task # 1 frame for the new call into the BRE or ET # 1 frame for the AsyncScope initialize that the BRE/ET has to be in # "./lib/aws/rubyflow/asyncBacktrace.rb:75:in `caller'" # "./lib/aws/rubyflow/asyncBacktrace.rb:21:in `create'" # "./lib/aws/rubyflow/flow.rb:16:in `make_backtrace'" # "./lib/aws/rubyflow/flow.rb:103:in `initialize'" # "./lib/aws/rubyflow/asyncScope.rb:17:in `new'" # "./lib/aws/rubyflow/asyncScope.rb:17:in `initialize'" frames_to_skip = 7 backtrace = AsyncBacktrace.create(parent_backtrace, frames_to_skip) end |
#task(future = nil, &block) ⇒ Future
Returns The tasks result, which is a Future.
31 32 33 34 35 36 37 38 39 |
# File 'lib/aws/flow/implementation.rb', line 31 def task(future = nil, &block) fiber = ::Fiber.current raise NoContextException unless fiber.respond_to? :__context__ context = fiber.__context__ t = Task.new(nil, &block) task_context = TaskContext.new(:parent => context.get_closest_containing_scope, :task => t) context << t t.result end |
#wait_for_all(*futures) ⇒ Array
Blocks until all of the arguments are set.
146 147 148 |
# File 'lib/aws/flow/implementation.rb', line 146 def wait_for_all(*futures) wait_for_function(lambda {|result, future_list| result.size == future_list.size}, futures) end |
#wait_for_any(*futures) ⇒ Array
Blocks until any of the arguments are set.
134 135 136 |
# File 'lib/aws/flow/implementation.rb', line 134 def wait_for_any(*futures) wait_for_function(lambda {|result, future_list| result.length >= 1 }, futures) end |
#wait_for_function(function, *futures) ⇒ Object
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'lib/aws/flow/implementation.rb', line 110 def wait_for_function(function, *futures) conditional = FiberConditionVariable.new futures.flatten! return nil if futures.empty? result = futures.select(&:set?) return futures.find(&:set?)if function.call(result, futures) futures.each do |f| f.on_set do |set_one| result << set_one conditional.broadcast if function.call(result, futures) end end conditional.wait result end |