Skip to content

Commit 1a9fd7f

Browse files
committed
Do not callback with final empty array until readyForQuery is received
Closes brianc/node-pg-query-stream#3
1 parent b1b39bb commit 1a9fd7f

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

index.js

+10-3
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,19 @@ Cursor.prototype.handleDataRow = function(msg) {
5050
Cursor.prototype._sendRows = function() {
5151
this.state = 'idle'
5252
setImmediate(function() {
53-
this._cb(null, this._rows)
53+
var cb = this._cb
54+
//remove callback before calling it
55+
//because likely a new one will be added
56+
//within the call to this callback
57+
this._cb = null
58+
if(cb) {
59+
cb(null, this._rows)
60+
}
5461
this._rows = []
5562
}.bind(this))
5663
}
5764

5865
Cursor.prototype.handleCommandComplete = function() {
59-
this._sendRows()
60-
this.state = 'done'
6166
this.connection.sync()
6267
}
6368

@@ -66,6 +71,8 @@ Cursor.prototype.handlePortalSuspended = function() {
6671
}
6772

6873
Cursor.prototype.handleReadyForQuery = function() {
74+
this._sendRows()
75+
this.state = 'done'
6976
}
7077

7178
Cursor.prototype.handleError = function(msg) {

0 commit comments

Comments
 (0)