@@ -39,13 +39,8 @@ module.exports = Postgres
39
39
function Postgres ( url , options ) {
40
40
options = parseOptions ( url , options )
41
41
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 ( )
49
44
, all = [ ]
50
45
, queries = Queue ( )
51
46
, listeners = { }
@@ -54,6 +49,12 @@ function Postgres(url, options) {
54
49
, isInsert = / ( ^ | [ ^ ) ( ] ) \s * i n s e r t \s + i n t o \s + [ ^ \s ] + \s * $ / i
55
50
, isSelect = / ( ^ | [ ^ ) ( ] ) \s * s e l e c t \s * $ / i
56
51
52
+ let ready = false
53
+ , ended = null
54
+ , arrayTypesPromise
55
+ , slots = max
56
+ , listener
57
+
57
58
function postgres ( xs ) {
58
59
return query ( { } , getConnection ( ) , xs , Array . from ( arguments ) . slice ( 1 ) )
59
60
}
@@ -186,12 +187,13 @@ function Postgres(url, options) {
186
187
}
187
188
188
189
function getConnection ( reserve ) {
189
- const connection = -- max >= 0 ? createConnection ( options ) : connections . shift ( )
190
+ const connection = slots ? createConnection ( options ) : connections . shift ( )
190
191
! reserve && connection && connections . push ( connection )
191
192
return connection
192
193
}
193
194
194
195
function createConnection ( options ) {
196
+ slots --
195
197
const connection = Connection ( options )
196
198
all . push ( connection )
197
199
return connection
0 commit comments