mirror of
https://gitea.invidious.io/iv-org/shard-crystal-db.git
synced 2024-08-15 00:53:32 +00:00
Use select / timeout in Crystal 0.34
This commit is contained in:
parent
af200eac54
commit
f4b298d3a5
1 changed files with 30 additions and 17 deletions
|
@ -206,25 +206,38 @@ module DB
|
||||||
@idle.first?
|
@idle.first?
|
||||||
end
|
end
|
||||||
|
|
||||||
private def wait_for_available
|
{% if compare_versions(Crystal::VERSION, "0.34.0-0") > 0 %}
|
||||||
timeout = TimeoutHelper.new(@checkout_timeout.to_f64)
|
private def wait_for_available
|
||||||
sync_inc_waiting_resource
|
sync_inc_waiting_resource
|
||||||
|
|
||||||
timeout.start
|
select
|
||||||
|
when @availability_channel.receive
|
||||||
# TODO update to select keyword for crystal 0.19
|
sync_dec_waiting_resource
|
||||||
index, _ = Channel.select(@availability_channel.receive_select_action, timeout.receive_select_action)
|
when timeout(@checkout_timeout.seconds)
|
||||||
case index
|
sync_dec_waiting_resource
|
||||||
when 0
|
raise DB::PoolTimeout.new
|
||||||
timeout.cancel
|
end
|
||||||
sync_dec_waiting_resource
|
|
||||||
when 1
|
|
||||||
sync_dec_waiting_resource
|
|
||||||
raise DB::PoolTimeout.new
|
|
||||||
else
|
|
||||||
raise DB::Error.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
|
private def sync_inc_waiting_resource
|
||||||
sync { @waiting_resource += 1 }
|
sync { @waiting_resource += 1 }
|
||||||
|
|
Loading…
Reference in a new issue