Class: AWS::Flow::Core::Future
- Inherits:
-
Object
- Object
- AWS::Flow::Core::Future
- Defined in:
- lib/aws/flow/future.rb
Overview
Represents the result of an asynchronous computation. Methods are provided to:
-
retrieve the result of the computation, once it is complete (#get).
-
check if the computation is complete (#set?)
-
execute a block when computation is complete (#on_set)
The result of a Future can only be retrieved when the computation has completed. #get blocks execution, if necessary, until the Future is ready. This is okay: because it will block that fiber, another fiber will start executing.
Instance Method Summary collapse
-
#get ⇒ Object
Blocks if future is not set.
-
#is_flow_future? ⇒ Boolean
private
Is the object is an AWS Flow future? AWS Flow futures must have a #get method.
-
#on_set(&block) ⇒ Object
Adds a callback, passed in as a block, which will fire when the future is set.
- #set(result = nil) ⇒ Object private
-
#set? ⇒ Boolean
True if the Future has been set.
-
#unset ⇒ Object
private
Unsets the future.
Instance Method Details
#get ⇒ Object
Blocks if future is not set. Returns the result of the future once #set is true.
64 65 66 67 68 69 70 |
# File 'lib/aws/flow/future.rb', line 64 def get until @set @conditional ||= FiberConditionVariable.new @conditional.wait end @result end |
#is_flow_future? ⇒ 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 object is an AWS Flow future? AWS Flow futures must have a #get method.
52 53 54 |
# File 'lib/aws/flow/future.rb', line 52 def is_flow_future? true end |
#on_set(&block) ⇒ Object
Adds a callback, passed in as a block, which will fire when the future is set.
88 89 90 91 92 |
# File 'lib/aws/flow/future.rb', line 88 def on_set(&block) @listeners ||= [] # TODO probably want to use lambda here @listeners << block end |
#set(result = nil) ⇒ 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.
Sets the value of the AWS::Flow::Core::Future, and notifies all of the fibers that tried to call #get when this future wasn’t ready.
40 41 42 43 44 45 46 47 |
# File 'lib/aws/flow/future.rb', line 40 def set(result=nil) raise AlreadySetException if @set @set = true @result = result @conditional.broadcast if @conditional @listeners.each { |b| b.call(self) } if @listeners self end |
#set? ⇒ Boolean
Returns true if the AWS::Flow::Core::Future has been set.
74 75 76 |
# File 'lib/aws/flow/future.rb', line 74 def set? @set end |
#unset ⇒ 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.
Unsets the future.
81 82 83 84 |
# File 'lib/aws/flow/future.rb', line 81 def unset @set = nil @result = nil end |