From b2e108571e40413889efdc03e05cc6fffe4676b0 Mon Sep 17 00:00:00 2001 From: jeromew Date: Sat, 30 Jul 2016 00:08:54 +0000 Subject: [PATCH] Issue #54: We should probably delay the _flush cb() to CommandComplete --- index.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 17b7237..ccac224 100644 --- a/index.js +++ b/index.js @@ -43,7 +43,7 @@ CopyStreamQuery.prototype._flush = function(cb) { var Int32Len = 4; var finBuffer = Buffer([code.CopyDone, 0, 0, 0, Int32Len]) this.push(finBuffer) - cb() + this.cb_flush = cb } CopyStreamQuery.prototype.handleError = function(e) { @@ -62,6 +62,10 @@ CopyStreamQuery.prototype.handleCommandComplete = function(msg) { this.rowCount = parseInt(match[1], 10) } + // we delay the _flush cb so that the 'end' event is + // triggered after CommandComplete + this.cb_flush() + // unpipe from connection this.unpipe(this.connection) this.connection = null