diff --git a/History.md b/History.md
index 85a11d24..548b5b0d 100644
--- a/History.md
+++ b/History.md
@@ -1,3 +1,7 @@
+# v0.4.1
+
+* Fixed race condition that occured if you called pause during a flush.
+
# v0.4.0
* Fixed misspelling of `delimiter` [#40](https://github.com/C2FO/fast-csv/issues/40)
diff --git a/docs/History.html b/docs/History.html
index fa780059..2795d4c8 100644
--- a/docs/History.html
+++ b/docs/History.html
@@ -176,6 +176,10 @@
+
v0.4.1
+
+- Fixed race condition that occured if you called pause during a flush.
+
v0.4.0
- Fixed misspelling of
delimiter
#40
diff --git a/lib/parser_stream.js b/lib/parser_stream.js
index 92cd2838..dc18af08 100644
--- a/lib/parser_stream.js
+++ b/lib/parser_stream.js
@@ -173,13 +173,24 @@ extended(ParserStream).extend({
}
},
+ __doFlush: function (callback) {
+ //increment row count so we aren't 0 based
+ this.emit("end");
+ callback();
+ },
+
_flush: function (callback) {
if (this.lines) {
this._parse(this.lines, false);
}
- //increment row count so we aren't 0 based
- this.emit("end");
- callback();
+ if (!this.paused) {
+ this.__doFlush(callback);
+ } else {
+ var self = this;
+ this.__pausedDone = function () {
+ self.__doFlush(callback);
+ };
+ }
},
__validate: function (data, index) {
diff --git a/package.json b/package.json
index bbba6d40..edf82a78 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "fast-csv",
- "version": "0.4.0",
+ "version": "0.4.1",
"description": "CSV parser and writer",
"main": "index.js",
"scripts": {