From cab956ba5030b146ea2132954588023b062ed02e Mon Sep 17 00:00:00 2001 From: Tom Buchok Date: Wed, 9 Apr 2014 23:58:18 -0400 Subject: [PATCH] passes `stream-tester-timestamp` - moves 'end' event listener to constructor, only listen once - ensures all existing tests still green --- index.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index f50f0af9..89d3aa9b 100644 --- a/index.js +++ b/index.js @@ -11,6 +11,9 @@ var QueryStream = module.exports = function(text, values, options) { }) this.batchSize = options.batchSize || 100 this._ready = false + this.once('end', function() { + setImmediate(function() { this.emit('close') }.bind(this)); + }) //kick reader this.read() } @@ -35,7 +38,6 @@ QueryStream.prototype._read = function(n) { if(!rows.length) { setImmediate(function() { self.push(null) - self.once('end', self.emit.bind(self, 'close')) }) } self._reading = false