@@ -111,7 +111,7 @@ class Pool extends EventEmitter {
111
111
return this . _clients . length >= this . options . max
112
112
}
113
113
114
- _pulseQueue ( ) {
114
+ _pulseQueue ( name ) {
115
115
this . log ( 'pulse queue' )
116
116
if ( this . ended ) {
117
117
this . log ( 'pulse queue ended' )
@@ -142,7 +142,10 @@ class Pool extends EventEmitter {
142
142
}
143
143
const pendingItem = this . _pendingQueue . shift ( )
144
144
if ( this . _idle . length ) {
145
- const idleItem = this . _idle . pop ( )
145
+ let idleItem = name ? this . _idle . find ( ( item ) => item . client . connection . parsedStatements [ name ] ) : null
146
+ if ( ! idleItem ) {
147
+ idleItem = this . _idle . pop ( )
148
+ }
146
149
clearTimeout ( idleItem . timeoutId )
147
150
const client = idleItem . client
148
151
client . ref && client . ref ( )
@@ -168,7 +171,7 @@ class Pool extends EventEmitter {
168
171
this . emit ( 'remove' , client )
169
172
}
170
173
171
- connect ( cb ) {
174
+ connect ( cb , name ) {
172
175
if ( this . ending ) {
173
176
const err = new Error ( 'Cannot use a pool after calling end on the pool' )
174
177
return cb ? cb ( err ) : this . Promise . reject ( err )
@@ -181,7 +184,7 @@ class Pool extends EventEmitter {
181
184
if ( this . _isFull ( ) || this . _idle . length ) {
182
185
// if we have idle clients schedule a pulse immediately
183
186
if ( this . _idle . length ) {
184
- process . nextTick ( ( ) => this . _pulseQueue ( ) )
187
+ process . nextTick ( ( ) => this . _pulseQueue ( name ) )
185
188
}
186
189
187
190
if ( ! this . options . connectionTimeoutMillis ) {
@@ -431,7 +434,7 @@ class Pool extends EventEmitter {
431
434
client . release ( err )
432
435
return cb ( err )
433
436
}
434
- } )
437
+ } , text . name )
435
438
return response . result
436
439
}
437
440
0 commit comments