class Seahorse::Client::AsyncResponse

Public Class Methods

new(options = {}) click to toggle source
# File lib/seahorse/client/async_response.rb, line 7
def initialize(options = {})
  @response = Response.new(context: options[:context])
  @stream = options[:stream]
  @stream_mutex = options[:stream_mutex]
  @close_condition = options[:close_condition]
  @sync_queue = options[:sync_queue]
end

Public Instance Methods

context() click to toggle source

@return [RequestContext]

# File lib/seahorse/client/async_response.rb, line 16
def context
  @response.context
end
error() click to toggle source

@return [StandardError, nil]

# File lib/seahorse/client/async_response.rb, line 21
def error
  @response.error
end
join!() click to toggle source
# File lib/seahorse/client/async_response.rb, line 69
def join!
  if error && context.config.raise_response_errors
    raise error
  elsif @stream
    # close callback is waiting
    # for the "sync_signal"
    @sync_queue << "sync_signal"
    @stream.close
    @response
  end
end
on(range, &block) click to toggle source

@overload on(status_code, &block)

@param [Integer] status_code The block will be
  triggered only for responses with the given status code.

@overload on(status_code_range, &block)

@param [Range<Integer>] status_code_range The block will be
  triggered only for responses with a status code that falls
  witin the given range.

@return [self]

# File lib/seahorse/client/async_response.rb, line 35
def on(range, &block)
  @response.on(range, &block)
  self
end
on_complete(&block) click to toggle source

@api private

# File lib/seahorse/client/async_response.rb, line 41
def on_complete(&block)
  @response.on_complete(&block)
  self
end
successful?() click to toggle source

@return [Boolean] Returns ‘true` if the response is complete with

no error.
# File lib/seahorse/client/async_response.rb, line 48
def successful?
  @response.error.nil?
end
wait() click to toggle source
# File lib/seahorse/client/async_response.rb, line 52
def wait
  if error && context.config.raise_response_errors
    raise error
  elsif @stream
    # have a sync signal that #signal can be blocked on
    # else, if #signal is called before #wait
    # will be waiting for a signal never arrives
    @sync_queue << "sync_signal"
    # now #signal is unlocked for
    # signaling close condition when ready
    @stream_mutex.synchronize {
      @close_condition.wait(@stream_mutex)
    }
    @response
  end
end