diff --git a/index.js b/index.js index 5ea42cf1..2d8e088b 100644 --- a/index.js +++ b/index.js @@ -32,14 +32,28 @@ Cursor.prototype.submit = function(connection) { }, true) con.flush() + + con.once('noData', ifNoData) + con.once('rowDescription', function () { + con.removeListener('noData', ifNoData); + }); + + function ifNoData () { + self.state = 'idle' + self._shiftQueue(); + } +} + +Cursor.prototype._shiftQueue = function () { + if(this._queue.length) { + this._getRows.apply(this, this._queue.shift()) + } } Cursor.prototype.handleRowDescription = function(msg) { this._result.addFields(msg.fields) this.state = 'idle' - if(this._queue.length) { - this._getRows.apply(this, this._queue.shift()) - } + this._shiftQueue(); } Cursor.prototype.handleDataRow = function(msg) {