Timeout faraday a simple reception

Is there a way to add a time-out settings in this simple method get?

I use Faraday 3.3.

Faraday.get(url)

After searching, I can apply the settings timeout only after I first initiates the connection, and then apply the settings timeout. Or is there an easier way?

That's what I'm doing right now:

conn = Faraday.new
response = conn.get do |req|
  req.url url
  req.options.timeout = 2 # 2 seconds
end
+4
source share
1 answer

Try the following:

conn = Faraday.new do |conn|
  conn.request.options.timeout = 20
end
response = conn.get(url)

UPD: After I looked at the sources of precious stones, I learned that there is no way to do it, how you want.

get url, . , @options Faraday::Connection. , attr_reader :options

conn = Faraday::Connection.new
conn.options.timeout = 20

Faraday:: :

Faraday::Connection.new(nil, request: { timeout: 20 })

:

Faraday::Connection.new.get(url) { |request| request.options.timeout = 20 }
+5

All Articles