Class: Krikri::AsyncUriGetter::Request

Inherits:
Struct
  • Object
show all
Defined in:
lib/krikri/async_uri_getter.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeRequest



76
77
78
79
# File 'lib/krikri/async_uri_getter.rb', line 76

def initialize(*)
  super
  @request_thread = start_request
end

Instance Attribute Details

#headersObject

Returns the value of attribute headers



75
76
77
# File 'lib/krikri/async_uri_getter.rb', line 75

def headers
  @headers
end

#optsObject

Returns the value of attribute opts



75
76
77
# File 'lib/krikri/async_uri_getter.rb', line 75

def opts
  @opts
end

#uriObject

Returns the value of attribute uri



75
76
77
# File 'lib/krikri/async_uri_getter.rb', line 75

def uri
  @uri
end

Instance Method Details

#joinObject

Wait for the request thread to complete



83
84
85
86
87
88
89
90
# File 'lib/krikri/async_uri_getter.rb', line 83

def join
  @request_thread.join
rescue => e
  # If the join throws an exception, the thread is dead anyway.  The
  # subsequent call to `with_response` will propagate the exception to the
  # calling thread.
  raise e unless inline_exceptions?
end

#with_response {|Faraday::Response| ... } ⇒ Object

Yields:

  • (Faraday::Response)

    the response returned for the request



94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'lib/krikri/async_uri_getter.rb', line 94

def with_response
  yield @request_thread.value
rescue => e
  if inline_exceptions?
    # Deliver an error response to the caller to allow uniform access
    msg = e.message + "\n\n" + e.backtrace.join("\n")
    yield Faraday::Response.new(status: 500,
                                body: msg,
                                response_headers: {
                                  'X-Exception' => e,
                                  'X-Exception-Message' => e.message,
                                  'X-Internal-Response' => 'true'
                                })
  else
    raise e
  end
end