From 734c84c3f596e52f08071689a557c26cd24fe7ef 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 786bd3c6..5dd169fd 100644 --- a/src/invidious/connection/pool.cr +++ b/src/invidious/connection/pool.cr @@ -34,7 +34,7 @@ module Invidious::ConnectionPool abstract def pool : DB::Pool(PoolClient) {% 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 | @@ -48,12 +48,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 %}