From 8d8952ad71f405e1d76431ced7ed3a0b398a9ac2 Mon Sep 17 00:00:00 2001 From: liaoweiqiang Date: Tue, 30 Jan 2018 23:14:25 +0800 Subject: [PATCH] handle finish and error events to avoid dead _flush loop --- lib/parse.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/parse.js b/lib/parse.js index 69fc2c4..f6a58ad 100644 --- a/lib/parse.js +++ b/lib/parse.js @@ -34,6 +34,14 @@ function Parse(opts) { self._streamFinish = true; }); + this.once('error',function () { + this.isError = true + }) + + this.once('finish',function () { + this.isFinish = true + }) + this._readRecord(); } @@ -296,7 +304,7 @@ Parse.prototype.pipe = function (dest, opts) { }; Parse.prototype._flush = function (callback) { - if (!this._streamEnd || !this._streamFinish) { + if (!this.isFinish && !this.isError &&( !this._streamEnd || !this._streamFinish)) { return setImmediate(this._flush.bind(this, callback)); }