Bump required Crystal to 0.35.0 (#135)

In order to use logging we need 0.35.0
This commit is contained in:
Brian J. Cardiff 2020-09-29 10:35:14 -03:00 committed by GitHub
parent 7253551849
commit 284145138f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 55 deletions

View file

@ -4,6 +4,6 @@ version: 0.9.0
authors:
- Brian J. Cardiff <bcardiff@manas.tech>
crystal: 0.25.0
crystal: 0.35.0
license: MIT

View file

@ -229,38 +229,17 @@ module DB
@idle.first?
end
{% if compare_versions(Crystal::VERSION, "0.34.0-0") > 0 %}
private def wait_for_available
sync_inc_waiting_resource
private def wait_for_available
sync_inc_waiting_resource
select
when @availability_channel.receive
sync_dec_waiting_resource
when timeout(@checkout_timeout.seconds)
sync_dec_waiting_resource
raise DB::PoolTimeout.new("Could not check out a connection in #{@checkout_timeout} seconds")
end
select
when @availability_channel.receive
sync_dec_waiting_resource
when timeout(@checkout_timeout.seconds)
sync_dec_waiting_resource
raise DB::PoolTimeout.new("Could not check out a connection in #{@checkout_timeout} seconds")
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("Could not check out a connection in #{@checkout_timeout} seconds")
else
raise DB::Error.new
end
end
{% end %}
end
private def sync_inc_waiting_resource
sync { @waiting_resource += 1 }
@ -291,29 +270,5 @@ module DB
@mutex.lock
end
end
class TimeoutHelper
def initialize(@timeout : Float64)
@abort_timeout = false
@timeout_channel = Channel(Nil).new
end
def receive_select_action
@timeout_channel.receive_select_action
end
def start
spawn do
sleep @timeout
unless @abort_timeout
@timeout_channel.send nil
end
end
end
def cancel
@abort_timeout = true
end
end
end
end