class AWS::Flow::Core::ExternalFuture

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. {ExternalFuture#get} blocks execution, if necessary, until the ExternalFuture is ready.

Unlike {Future}, {ExternalFuture#get} doesn’t block Fibers. Instead it blocks the current thread by waiting on a ruby {ConditionVariable}. The condition variable is signalled when the future is set, which allows the thread to continue execution when the result is ready. This lets us use the future outside of an {AsyncScope}

Public Class Methods

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

Public Instance Methods

get(timeout=nil) 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 174
def get(timeout=nil)
  @mutex.synchronize do
    unless @set
      @conditional.wait(@mutex, timeout)
      raise Timeout::Error.new unless @set
    end
  end
  @result
end
method_missing(method, *args, &block) click to toggle source
Calls superclass method
# File lib/aws/flow/future.rb, line 184
def method_missing(method, *args, &block)
  @mutex.synchronize do
    super(method, *args, &block)
  end
end