Skip to content

Commit

Permalink
Merge pull request #5 from guzba/ryan
Browse files Browse the repository at this point in the history
proc doc comments
  • Loading branch information
guzba authored Aug 29, 2023
2 parents cc97240 + c7f0f93 commit 8427060
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/ready/pools.nim
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ type
RedisPool* = ptr RedisPoolObj

proc close*(pool: RedisPool) =
## Closes the database connections in the pool then deallocates the pool.
## Closes the Redis connections in the pool then deallocates the pool.
## All connections should be returned to the pool before it is closed.
withLock pool.lock:
for conn in pool.conns:
Expand All @@ -29,6 +29,7 @@ proc openNewConnection(pool: RedisPool): RedisConn =
pool.onConnect(result)

proc recycle*(pool: RedisPool, conn: RedisConn) {.raises: [], gcsafe.} =
## Returns a Redis connection to the pool.
withLock pool.lock:
pool.conns.add(conn)
pool.r.shuffle(pool.conns)
Expand Down Expand Up @@ -64,6 +65,10 @@ proc newRedisPool*(
raise getCurrentException()

proc borrow*(pool: RedisPool): RedisConn {.gcsafe.} =
## Removes a Redis connection from the pool. This call blocks until it can take
## a connection. Remember to add the connection back to the pool with recycle
## when you're finished with it.

acquire(pool.lock)
while pool.conns.len == 0:
wait(pool.cond, pool.lock)
Expand Down

0 comments on commit 8427060

Please sign in to comment.