Class: Krikri::AsyncUriGetter::Request
- Inherits:
-
Struct
- Object
- Struct
- Krikri::AsyncUriGetter::Request
- Defined in:
- lib/krikri/async_uri_getter.rb
Instance Attribute Summary collapse
-
#headers ⇒ Object
Returns the value of attribute headers.
-
#opts ⇒ Object
Returns the value of attribute opts.
-
#uri ⇒ Object
Returns the value of attribute uri.
Instance Method Summary collapse
-
#initialize ⇒ Request
constructor
A new instance of Request.
-
#join ⇒ Object
Wait for the request thread to complete.
- #with_response {|Faraday::Response| ... } ⇒ Object
Constructor Details
#initialize ⇒ Request
Returns a new instance of Request.
76 77 78 79 |
# File 'lib/krikri/async_uri_getter.rb', line 76 def initialize(*) super @request_thread = start_request end |
Instance Attribute Details
#headers ⇒ Object
Returns the value of attribute headers
75 76 77 |
# File 'lib/krikri/async_uri_getter.rb', line 75 def headers @headers end |
#opts ⇒ Object
Returns the value of attribute opts
75 76 77 |
# File 'lib/krikri/async_uri_getter.rb', line 75 def opts @opts end |
#uri ⇒ Object
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
#join ⇒ Object
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
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/krikri/async_uri_getter.rb', line 94 def with_response begin response = @request_thread.value rescue => e if inline_exceptions? # Deliver an error response to the caller to allow uniform access msg = e. + "\n\n" + e.backtrace.join("\n") response = Faraday::Response.new(status: 500, body: msg, response_headers: { 'X-Exception' => e, 'X-Exception-Message' => e., 'X-Internal-Response' => 'true' }) else raise e end end yield response end |