mirror of
https://gitea.invidious.io/iv-org/shard-crystal-db.git
synced 2024-08-15 00:53:32 +00:00
Less state, less bugs
This commit is contained in:
parent
27d9ca0a84
commit
a5476338b1
1 changed files with 0 additions and 15 deletions
|
@ -57,8 +57,6 @@ module DB
|
||||||
|
|
||||||
# communicate that a connection is available for checkout
|
# communicate that a connection is available for checkout
|
||||||
@availability_channel : Channel(Nil)
|
@availability_channel : Channel(Nil)
|
||||||
# signal how many existing connections are waited for
|
|
||||||
@waiting_resource : Int32
|
|
||||||
# global pool mutex
|
# global pool mutex
|
||||||
@mutex : Mutex
|
@mutex : Mutex
|
||||||
|
|
||||||
|
@ -82,7 +80,6 @@ module DB
|
||||||
@retry_delay = pool_options.retry_delay
|
@retry_delay = pool_options.retry_delay
|
||||||
|
|
||||||
@availability_channel = Channel(Nil).new
|
@availability_channel = Channel(Nil).new
|
||||||
@waiting_resource = 0
|
|
||||||
@inflight = 0
|
@inflight = 0
|
||||||
@mutex = Mutex.new
|
@mutex = Mutex.new
|
||||||
|
|
||||||
|
@ -284,25 +281,13 @@ module DB
|
||||||
end
|
end
|
||||||
|
|
||||||
private def wait_for_available
|
private def wait_for_available
|
||||||
sync_inc_waiting_resource
|
|
||||||
|
|
||||||
select
|
select
|
||||||
when @availability_channel.receive
|
when @availability_channel.receive
|
||||||
sync_dec_waiting_resource
|
|
||||||
when timeout(@checkout_timeout.seconds)
|
when timeout(@checkout_timeout.seconds)
|
||||||
sync_dec_waiting_resource
|
|
||||||
raise DB::PoolTimeout.new("Could not check out a connection in #{@checkout_timeout} seconds")
|
raise DB::PoolTimeout.new("Could not check out a connection in #{@checkout_timeout} seconds")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
private def sync_inc_waiting_resource
|
|
||||||
sync { @waiting_resource += 1 }
|
|
||||||
end
|
|
||||||
|
|
||||||
private def sync_dec_waiting_resource
|
|
||||||
sync { @waiting_resource -= 1 }
|
|
||||||
end
|
|
||||||
|
|
||||||
private def sync
|
private def sync
|
||||||
@mutex.lock
|
@mutex.lock
|
||||||
begin
|
begin
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue