Do not callback with final empty array until readyForQuery is received

Closes https://github.com/brianc/node-pg-query-stream/issues/3
This commit is contained in:
Brian M. Carlson 2014-03-21 11:44:46 -05:00
parent b1b39bbd4f
commit 1a9fd7ff76

View File

@ -50,14 +50,19 @@ Cursor.prototype.handleDataRow = function(msg) {
Cursor.prototype._sendRows = function() {
this.state = 'idle'
setImmediate(function() {
this._cb(null, this._rows)
var cb = this._cb
//remove callback before calling it
//because likely a new one will be added
//within the call to this callback
this._cb = null
if(cb) {
cb(null, this._rows)
}
this._rows = []
}.bind(this))
}
Cursor.prototype.handleCommandComplete = function() {
this._sendRows()
this.state = 'done'
this.connection.sync()
}
@ -66,6 +71,8 @@ Cursor.prototype.handlePortalSuspended = function() {
}
Cursor.prototype.handleReadyForQuery = function() {
this._sendRows()
this.state = 'done'
}
Cursor.prototype.handleError = function(msg) {