Class: Seahorse::Client::AsyncResponse

Inherits:
Object
  • Object
show all
Defined in:
lib/seahorse/client/async_response.rb

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ AsyncResponse

Returns a new instance of AsyncResponse.



7
8
9
10
11
12
13
# 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

Instance Method Details

#contextRequestContext

Returns:



16
17
18
# File 'lib/seahorse/client/async_response.rb', line 16

def context
  @response.context
end

#errorStandardError?

Returns:

  • (StandardError, nil)


21
22
23
# File 'lib/seahorse/client/async_response.rb', line 21

def error
  @response.error
end

#join!Object



69
70
71
72
73
74
75
76
77
78
79
# 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(status_code, &block) ⇒ self #on(status_code_range, &block) ⇒ self

Overloads:

  • #on(status_code, &block) ⇒ self

    Parameters:

    • status_code (Integer)

      The block will be triggered only for responses with the given status code.

  • #on(status_code_range, &block) ⇒ self

    Parameters:

    • status_code_range (Range<Integer>)

      The block will be triggered only for responses with a status code that falls witin the given range.

Returns:

  • (self)


35
36
37
38
# File 'lib/seahorse/client/async_response.rb', line 35

def on(range, &block)
  @response.on(range, &block)
  self
end

#on_complete(&block) ⇒ 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.



41
42
43
44
# File 'lib/seahorse/client/async_response.rb', line 41

def on_complete(&block)
  @response.on_complete(&block)
  self
end

#successful?Boolean

Returns ‘true` if the response is complete with no error.

Returns:

  • (Boolean)

    Returns ‘true` if the response is complete with no error.



48
49
50
# File 'lib/seahorse/client/async_response.rb', line 48

def successful?
  @response.error.nil?
end

#waitObject



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# 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