Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions lib/sql-client-pool.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,12 @@ class SQLClientPool
if not @pool_is_open
callback new Error(@MESSAGES.POOL_NOT_OPEN)
else
if @active >= @pool_options.max_active and @pool_options.when_exhausted is 'fail'
@active++
if @active > @pool_options.max_active and @pool_options.when_exhausted is 'fail'
@active--
callback new Error(@MESSAGES.EXHAUSTED)
else if @active >= @pool_options.max_active and @pool_options.when_exhausted is 'block'
else if @active > @pool_options.max_active and @pool_options.when_exhausted is 'block'
@active--
if blocked_since? and (Date.now() - blocked_since) >= @pool_options.max_wait
callback new Error(@MESSAGES.MAX_WAIT)
else
Expand All @@ -117,31 +120,34 @@ class SQLClientPool
client = @pool.shift()
@_activate_and_validate_or_destroy client, (err,valid,client)=>
if err?
@active--
callback(err)
else if not valid
@active--
@borrow(callback)
else
client.pooled_at = null
client.borrowed_at = Date.now()
@active++
callback(null,client)
else
@create (err,client)=>
if err?
@active--
callback(err)
else
@_activate_and_validate_or_destroy client, (err,valid,client)=>
if err?
@active--
callback(err)
else if not valid
@active--
if @pool_options.max_retries? and @pool_options.max_retries > retry_count
setTimeout (()=>@borrow(callback,blocked_since,retry_count+1)), (@pool_options.retry_interval ? 0)
else
callback new Error(@MESSAGES.INVALID)
else
client.pooled_at = null
client.borrowed_at = Date.now()
@active++
callback(null,client)

return:(client,callback)=>
Expand Down