Skip to content

Commit

Permalink
Merge pull request #124 from crystal-lang/crystal/0.34.0
Browse files Browse the repository at this point in the history
Crystal 0.34.0 support
  • Loading branch information
Brian J. Cardiff authored Apr 6, 2020
2 parents f08a4da + f4b298d commit 7543908
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 18 deletions.
2 changes: 2 additions & 0 deletions spec/dummy_driver_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
49 changes: 31 additions & 18 deletions src/db/pool.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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

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
{% if compare_versions(Crystal::VERSION, "0.34.0-0") > 0 %}
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
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 }
Expand Down
2 changes: 2 additions & 0 deletions src/spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,8 @@ module DB
end
end
end
else
raise "Invalid prepared value. Allowed values are :both and :default"
end
end
end
Expand Down

0 comments on commit 7543908

Please sign in to comment.