Class: Async::HTTP::Faraday::Adapter
- Inherits:
-
Faraday::Adapter
- Object
- Faraday::Adapter
- Async::HTTP::Faraday::Adapter
- Defined in:
- lib/async/http/faraday/adapter.rb
Overview
An adapter that allows Faraday to use Async::HTTP as the underlying HTTP client.
Constant Summary collapse
- CONNECTION_EXCEPTIONS =
The exceptions that are considered connection errors and result in a
Faraday::ConnectionFailedexception. [ Errno::EADDRNOTAVAIL, Errno::ECONNABORTED, Errno::ECONNREFUSED, Errno::ECONNRESET, Errno::EHOSTUNREACH, Errno::EINVAL, Errno::ENETUNREACH, Errno::EPIPE, IOError, SocketError ].freeze
Instance Attribute Summary collapse
-
#read_timeout ⇒ Object
readonly
Returns the value of attribute read_timeout.
- #The maximum time to send a request and wait for a response.(maximumtimetosendarequest) ⇒ Object readonly
- #The maximum time to wait for an individual IO operation.(maximumtimetowait) ⇒ Object readonly
-
#timeout ⇒ Object
readonly
Returns the value of attribute timeout.
Class Method Summary collapse
-
.setup_parallel_manager(**options) ⇒ Object
Create a new parallel manager, which is used to handle multiple concurrent requests.
Instance Method Summary collapse
-
#call(env) ⇒ Object
Make a request using the adapter.
-
#close ⇒ Object
Close all clients.
-
#initialize ⇒ Adapter
constructor
Create a Faraday compatible adapter.
Constructor Details
#initialize ⇒ Adapter
Create a Faraday compatible adapter.
124 125 126 127 128 129 130 131 132 133 134 135 |
# File 'lib/async/http/faraday/adapter.rb', line 124 def initialize(...) super @timeout = @connection_options.delete(:timeout) @read_timeout = @connection_options.delete(:read_timeout) if clients = @connection_options.delete(:clients) @clients = clients.call(**@connection_options, &@config_block) else @clients = PerThreadPersistentClients.new(**@connection_options, &@config_block) end end |
Instance Attribute Details
#read_timeout ⇒ Object (readonly)
Returns the value of attribute read_timeout.
141 142 143 |
# File 'lib/async/http/faraday/adapter.rb', line 141 def read_timeout @read_timeout end |
#The maximum time to send a request and wait for a response.(maximumtimetosendarequest) ⇒ Object (readonly)
138 |
# File 'lib/async/http/faraday/adapter.rb', line 138 attr :timeout |
#The maximum time to wait for an individual IO operation.(maximumtimetowait) ⇒ Object (readonly)
141 |
# File 'lib/async/http/faraday/adapter.rb', line 141 attr :read_timeout |
#timeout ⇒ Object (readonly)
Returns the value of attribute timeout.
138 139 140 |
# File 'lib/async/http/faraday/adapter.rb', line 138 def timeout @timeout end |
Class Method Details
.setup_parallel_manager(**options) ⇒ Object
Create a new parallel manager, which is used to handle multiple concurrent requests.
102 103 104 |
# File 'lib/async/http/faraday/adapter.rb', line 102 def self.setup_parallel_manager(**) ParallelManager.new() end |
Instance Method Details
#call(env) ⇒ Object
Make a request using the adapter.
155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 |
# File 'lib/async/http/faraday/adapter.rb', line 155 def call(env) super # For compatibility with the default adapter: env.url.path = "/" if env.url.path.empty? if parallel_manager = env.parallel_manager parallel_manager.async do perform_request(env) env.response.finish(env) end else perform_request(env) end @app.call(env) end |
#close ⇒ Object
Close all clients.
144 145 146 147 |
# File 'lib/async/http/faraday/adapter.rb', line 144 def close # The order of operations here is to avoid a race condition between iterating over clients (#close may yield) and creating new clients. @clients.close end |