class AWS::Flow::Core::Future

Represents the result of an asynchronous computation. Methods are provided to:

The result of a Future can only be retrieved when the computation has completed. {Future#get} blocks execution, if necessary, until the Future is ready. This is okay: because it will block that fiber, another fiber will start executing.

Public Class Methods

new() click to toggle source
# File lib/aws/flow/future.rb, line 37
def initialize
  @conditional = FiberConditionVariable.new
  @set = false
end

Public Instance Methods

get() click to toggle source

Blocks if future is not set. Returns the result of the future once {#set} is true.

@return

The result of the future.

@raise CancellationError

when the task is cancelled.
# File lib/aws/flow/future.rb, line 69
def get
  @conditional.wait until @set
  @result
end
is_flow_future?() click to toggle source

Is the object is an AWS Flow future? AWS Flow futures must have a {#get} method. @api private

# File lib/aws/flow/future.rb, line 57
def is_flow_future?
  true
end
on_set(&block) click to toggle source

Adds a callback, passed in as a block, which will fire when the future is set.

# File lib/aws/flow/future.rb, line 90
def on_set(&block)
  @listeners ||= []
  # TODO probably want to use lambda here
  @listeners << block
end
set(result=nil) click to toggle source

Sets the value of the {Future}, and notifies all of the fibers that tried to call {#get} when this future wasn’t ready. @api private

# File lib/aws/flow/future.rb, line 45
def set(result=nil)
  raise AlreadySetException if @set
  @set = true
  @result = result
  @listeners.each { |b| b.call(self) } if @listeners
  @conditional.broadcast if @conditional
  self
end
set?() click to toggle source

@return

true if the {Future} has been set.
# File lib/aws/flow/future.rb, line 76
def set?
  @set
end
unset() click to toggle source

Unsets the future.

@api private

# File lib/aws/flow/future.rb, line 83
def unset
  @set = false
  @result = nil
end