Pool changes

This commit is contained in:
Chris Watson 2020-06-19 13:11:42 -06:00
parent 66ecb0e33b
commit 03f561b480
1 changed files with 3 additions and 5 deletions

View File

@ -46,12 +46,10 @@ module Arachnid
# throw an `IO::TimeoutError` if a request is made and a new client isn't fetched in time. # throw an `IO::TimeoutError` if a request is made and a new client isn't fetched in time.
def request(method, url : String | URI, headers = nil) def request(method, url : String | URI, headers = nil)
uri = url.is_a?(URI) ? url : URI.parse(url) uri = url.is_a?(URI) ? url : URI.parse(url)
pool = pool_for(url)
client = pool.checkout
headers = headers ? @request_headers.merge(headers) : @request_headers headers = headers ? @request_headers.merge(headers) : @request_headers
response = client.exec(method.to_s.upcase, uri.full_path, headers: headers) pool_for(url).use do |client|
pool.checkin(client) client.exec(method.to_s.upcase, uri.full_path, headers: headers)
response end
end end
# Retrieve the connection pool for the given `URI`. # Retrieve the connection pool for the given `URI`.