From aab9719e25eda3b2a8a410125c35a6dd25cc08a6 Mon Sep 17 00:00:00 2001 From: syeopite Date: Thu, 14 Nov 2024 17:21:04 -0800 Subject: [PATCH] Pool: Refactor logic for request methods Make non-block request method internally call the block based request method. --- src/invidious/connection/pool.cr | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/invidious/connection/pool.cr b/src/invidious/connection/pool.cr index a0ddfa70..611b4458 100644 --- a/src/invidious/connection/pool.cr +++ b/src/invidious/connection/pool.cr @@ -25,7 +25,7 @@ module Invidious::ConnectionPool end {% for method in %w[get post put patch delete head options] %} - def {{method.id}}(*args, **kwargs) + def {{method.id}}(*args, **kwargs, &) self.client do | client | client.{{method.id}}(*args, **kwargs) do | response | @@ -39,12 +39,10 @@ module Invidious::ConnectionPool end def {{method.id}}(*args, **kwargs) - self.client do | client | - return response = client.{{method.id}}(*args, **kwargs) + {{method.id}}(*args, **kwargs) do | response | + return response ensure - if response - response.body_io?.try &. skip_to_end - end + response.body_io?.try &. skip_to_end end end {% end %}