Skip to content

Commit

Permalink
Merge pull request #11 from guzba/ryan
Browse files Browse the repository at this point in the history
improvement
  • Loading branch information
guzba authored Jan 23, 2024
2 parents 42e3e9c + be68897 commit 7429c32
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions src/ready/pools.nim
Original file line number Diff line number Diff line change
Expand Up @@ -69,17 +69,16 @@ proc borrow*(pool: RedisPool): RedisConn {.gcsafe.} =
## a connection. Remember to add the connection back to the pool with recycle
## when you're finished with it.

var lastReturned: float
acquire(pool.lock)
while pool.conns.len == 0:
wait(pool.cond, pool.lock)
result = pool.conns.pop()
lastReturned = pool.lastReturned.getOrDefault(result, 0)
release(pool.lock)

if pool.onBorrow != nil:
try:
var lastReturned: float
withLock pool.lock:
lastReturned = pool.lastReturned[result]
pool.onBorrow(result, lastReturned)
except:
# Close this connection and open a new one
Expand Down

0 comments on commit 7429c32

Please sign in to comment.