From af200eac54161e1e2134cfc590ab1d31193e77a4 Mon Sep 17 00:00:00 2001 From: "Brian J. Cardiff" Date: Thu, 2 Apr 2020 12:34:15 -0300 Subject: [PATCH 1/2] Comply exhaustive case check Comply exhaustive case check --- spec/dummy_driver_spec.cr | 2 ++ src/spec.cr | 2 ++ 2 files changed, 4 insertions(+) diff --git a/spec/dummy_driver_spec.cr b/spec/dummy_driver_spec.cr index 688a71d..41f4d10 100644 --- a/spec/dummy_driver_spec.cr +++ b/spec/dummy_driver_spec.cr @@ -246,6 +246,8 @@ describe DummyDriver do rs.read(Int64, Int64).should eq({3i64, 4i64}) when 1 rs.read(Int64, Int64).should eq({1i64, 2i64}) + else + raise "unreachable" end i += 1 end diff --git a/src/spec.cr b/src/spec.cr index b8c64c2..225a419 100644 --- a/src/spec.cr +++ b/src/spec.cr @@ -505,6 +505,8 @@ module DB end end end + else + raise "Invalid prepared value. Allowed values are :both and :default" end end end From f4b298d3a5a6c555e02fd681e5f0da6680e44e84 Mon Sep 17 00:00:00 2001 From: "Brian J. Cardiff" Date: Wed, 25 Mar 2020 10:56:03 -0300 Subject: [PATCH 2/2] Use select / timeout in Crystal 0.34 --- src/db/pool.cr | 47 ++++++++++++++++++++++++++++++----------------- 1 file changed, 30 insertions(+), 17 deletions(-) diff --git a/src/db/pool.cr b/src/db/pool.cr index 5acffaa..75a8f93 100644 --- a/src/db/pool.cr +++ b/src/db/pool.cr @@ -206,25 +206,38 @@ module DB @idle.first? end - private def wait_for_available - timeout = TimeoutHelper.new(@checkout_timeout.to_f64) - sync_inc_waiting_resource + {% if compare_versions(Crystal::VERSION, "0.34.0-0") > 0 %} + private def wait_for_available + sync_inc_waiting_resource - timeout.start - - # TODO update to select keyword for crystal 0.19 - index, _ = Channel.select(@availability_channel.receive_select_action, timeout.receive_select_action) - case index - when 0 - timeout.cancel - sync_dec_waiting_resource - when 1 - sync_dec_waiting_resource - raise DB::PoolTimeout.new - else - raise DB::Error.new + select + when @availability_channel.receive + sync_dec_waiting_resource + when timeout(@checkout_timeout.seconds) + sync_dec_waiting_resource + raise DB::PoolTimeout.new + end end - end + {% else %} + private def wait_for_available + timeout = TimeoutHelper.new(@checkout_timeout.to_f64) + sync_inc_waiting_resource + + timeout.start + + index, _ = Channel.select(@availability_channel.receive_select_action, timeout.receive_select_action) + case index + when 0 + timeout.cancel + sync_dec_waiting_resource + when 1 + sync_dec_waiting_resource + raise DB::PoolTimeout.new + else + raise DB::Error.new + end + end + {% end %} private def sync_inc_waiting_resource sync { @waiting_resource += 1 }