From 208b229a3a58297dfb1c23d75b704e84619acaa4 Mon Sep 17 00:00:00 2001 From: John MacAslan Date: Tue, 3 Mar 2015 12:58:19 -0500 Subject: [PATCH] fixed support for aborting parsing --- papaparse.js | 8 +++++++- tests/test-cases.js | 5 ++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/papaparse.js b/papaparse.js index e6a4d05..3a7275a 100644 --- a/papaparse.js +++ b/papaparse.js @@ -390,7 +390,7 @@ var results = this._handle.parse(aggregate, this._baseIndex, !this._finished); - if (this._handle.paused()) + if (this._handle.paused() || this._handle.aborted()) return; var lastIndex = results.meta.cursor; @@ -658,6 +658,7 @@ var _input; // The input being parsed var _parser; // The core parser being used var _paused = false; // Whether we are paused or not + var _aborted = false; // Whether the parser has aborted or not var _delimiterError; // Temporary state between delimiter detection and processing results var _fields = []; // Fields are from the header row of the input, if there is one var _results = { // The last results returned from the parser @@ -743,8 +744,13 @@ self.streamer.parseChunk(_input); }; + this.aborted = function () { + return _aborted; + } + this.abort = function() { + _aborted = true; _parser.abort(); if (isFunction(_config.complete)) _config.complete(_results); diff --git a/tests/test-cases.js b/tests/test-cases.js index 524f991..355f215 100644 --- a/tests/test-cases.js +++ b/tests/test-cases.js @@ -1227,10 +1227,9 @@ var CUSTOM_TESTS = [ step: function(response, handle) { updates.push(response.data[0]); handle.abort(); - }, - complete: function() { callback(updates); - } + }, + chunkSize: 6 }); } },