From 03f561b480874393bae97341abc011ccfc877597 Mon Sep 17 00:00:00 2001 From: Chris Watson Date: Fri, 19 Jun 2020 13:11:42 -0600 Subject: [PATCH] Pool changes --- src/arachnid/request_handler.cr | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/arachnid/request_handler.cr b/src/arachnid/request_handler.cr index bca332e..682aa64 100644 --- a/src/arachnid/request_handler.cr +++ b/src/arachnid/request_handler.cr @@ -46,12 +46,10 @@ module Arachnid # 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) uri = url.is_a?(URI) ? url : URI.parse(url) - pool = pool_for(url) - client = pool.checkout headers = headers ? @request_headers.merge(headers) : @request_headers - response = client.exec(method.to_s.upcase, uri.full_path, headers: headers) - pool.checkin(client) - response + pool_for(url).use do |client| + client.exec(method.to_s.upcase, uri.full_path, headers: headers) + end end # Retrieve the connection pool for the given `URI`.