@@ -27,6 +27,8 @@ var Client = function(config) {
27
27
ssl : this . connectionParameters . ssl
28
28
} ) ;
29
29
this . queryQueue = [ ] ;
30
+ this . sentQueryQueue = [ ] ;
31
+ this . sendImmediately = true ;
30
32
this . binary = c . binary || defaults . binary ;
31
33
this . encoding = 'utf8' ;
32
34
this . processID = null ;
@@ -154,6 +156,7 @@ Client.prototype.connect = function(callback) {
154
156
var activeQuery = self . activeQuery ;
155
157
self . activeQuery = null ;
156
158
self . readyForQuery = true ;
159
+ self . handshakeDone = true ;
157
160
self . _pulseQueryQueue ( ) ;
158
161
if ( activeQuery ) {
159
162
activeQuery . handleReadyForQuery ( ) ;
@@ -279,20 +282,32 @@ Client.prototype.escapeLiteral = function(str) {
279
282
} ;
280
283
281
284
Client . prototype . _pulseQueryQueue = function ( ) {
285
+ if ( ! this . handshakeDone )
286
+ return ;
287
+
288
+ while ( ( this . sendImmediately && ! this . blocked ) || ( this . activeQuery === null && this . sentQueryQueue . length === 0 ) ) {
289
+ var query = this . queryQueue . shift ( ) ;
290
+ if ( ! query )
291
+ break ;
292
+
293
+ query . submit ( this . connection ) ;
294
+ this . blocked = query . blocking ;
295
+ this . sentQueryQueue . push ( query ) ;
296
+ }
297
+
282
298
if ( this . readyForQuery === true ) {
283
- this . activeQuery = this . queryQueue . shift ( ) ;
299
+ this . activeQuery = this . sentQueryQueue . shift ( ) ;
284
300
if ( this . activeQuery ) {
285
301
this . readyForQuery = false ;
286
302
this . hasExecuted = true ;
287
- this . activeQuery . submit ( this . connection ) ;
288
303
} else if ( this . hasExecuted ) {
289
304
this . activeQuery = null ;
290
305
this . emit ( 'drain' ) ;
291
306
}
292
307
}
293
308
} ;
294
309
295
- Client . prototype . _copy = function ( text , stream ) {
310
+ Client . prototype . _copy = function ( text , stream , blocking ) {
296
311
var config = { } ;
297
312
config . text = text ;
298
313
config . stream = stream ;
@@ -304,14 +319,14 @@ Client.prototype._copy = function (text, stream) {
304
319
}
305
320
} ;
306
321
var query = new Query ( config ) ;
322
+ query . blocking = blocking ;
307
323
this . queryQueue . push ( query ) ;
308
324
this . _pulseQueryQueue ( ) ;
309
325
return config . stream ;
310
-
311
326
} ;
312
327
313
328
Client . prototype . copyFrom = function ( text ) {
314
- return this . _copy ( text , new CopyFromStream ( ) ) ;
329
+ return this . _copy ( text , new CopyFromStream ( ) , true ) ;
315
330
} ;
316
331
317
332
Client . prototype . copyTo = function ( text ) {
0 commit comments