You are viewing documentation for version 3 of the AWS SDK for Ruby. Version 2 documentation can be found here.

Class: Seahorse::Client::AsyncResponse

Inherits:
Object
  • Object
show all
Defined in:
gems/aws-sdk-core/lib/seahorse/client/async_response.rb

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ AsyncResponse

Returns a new instance of AsyncResponse



5
6
7
8
9
10
11
# File 'gems/aws-sdk-core/lib/seahorse/client/async_response.rb', line 5

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

#contextObject



13
14
15
# File 'gems/aws-sdk-core/lib/seahorse/client/async_response.rb', line 13

def context
  @response.context
end

#errorObject



17
18
19
# File 'gems/aws-sdk-core/lib/seahorse/client/async_response.rb', line 17

def error
  @response.error
end

#join!Object



48
49
50
51
52
53
54
55
56
57
58
# File 'gems/aws-sdk-core/lib/seahorse/client/async_response.rb', line 48

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) ⇒ Object



21
22
23
24
# File 'gems/aws-sdk-core/lib/seahorse/client/async_response.rb', line 21

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

#on_complete(&block) ⇒ Object



26
27
28
29
# File 'gems/aws-sdk-core/lib/seahorse/client/async_response.rb', line 26

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

#waitObject



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'gems/aws-sdk-core/lib/seahorse/client/async_response.rb', line 31

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