Skip to content

Commit e8a51a5

Browse files
committed
Remove infinite decrement
1 parent 1021a36 commit e8a51a5

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

lib/index.js

+10-8
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,8 @@ module.exports = Postgres
3939
function Postgres(url, options) {
4040
options = parseOptions(url, options)
4141

42-
let ready = false
43-
, ended = null
44-
, arrayTypesPromise
45-
, max = Math.max(1, options.max)
46-
, listener
47-
48-
const connections = Queue()
42+
const max = Math.max(1, options.max)
43+
, connections = Queue()
4944
, all = []
5045
, queries = Queue()
5146
, listeners = {}
@@ -54,6 +49,12 @@ function Postgres(url, options) {
5449
, isInsert = /(^|[^)(])\s*insert\s+into\s+[^\s]+\s*$/i
5550
, isSelect = /(^|[^)(])\s*select\s*$/i
5651

52+
let ready = false
53+
, ended = null
54+
, arrayTypesPromise
55+
, slots = max
56+
, listener
57+
5758
function postgres(xs) {
5859
return query({}, getConnection(), xs, Array.from(arguments).slice(1))
5960
}
@@ -186,12 +187,13 @@ function Postgres(url, options) {
186187
}
187188

188189
function getConnection(reserve) {
189-
const connection = --max >= 0 ? createConnection(options) : connections.shift()
190+
const connection = slots ? createConnection(options) : connections.shift()
190191
!reserve && connection && connections.push(connection)
191192
return connection
192193
}
193194

194195
function createConnection(options) {
196+
slots--
195197
const connection = Connection(options)
196198
all.push(connection)
197199
return connection

0 commit comments

Comments
 (0)