Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions papaparse.js
Original file line number Diff line number Diff line change
Expand Up @@ -568,8 +568,8 @@ License: MIT
this._halted = true;
return;
}
this._completeResults = results;
results = undefined;
this._completeResults = undefined;
}

if (!this._config.step && !this._config.chunk) {
Expand Down Expand Up @@ -1866,23 +1866,23 @@ License: MIT
if (aborted)
break;
}
delete msg.results; // free memory ASAP
}
else if (isFunction(worker.userChunk))
{
worker.userChunk(msg.results, handle, msg.file);
delete msg.results;
}
}

if (msg.finished && !aborted)
completeWorker(msg.workerId, msg.results);
completeWorker(msg.workerId, msg.results, msg.file);

delete msg.results;
}

function completeWorker(workerId, results) {
function completeWorker(workerId, results, file) {
var worker = workers[workerId];
if (isFunction(worker.userComplete))
worker.userComplete(results);
worker.userComplete(results, file);
worker.terminate();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you elaborate why wee need to terminate the worker only when a function is defined?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I may have unintentionally changed the original flow while modifying the code. I'll revert back to. Thank you.

delete workers[workerId];
}
Expand Down
24 changes: 24 additions & 0 deletions tests/test-cases.js
Original file line number Diff line number Diff line change
Expand Up @@ -2741,6 +2741,30 @@ var CUSTOM_TESTS = [
});
}
},
{
description: "Result is properly passed to complete callback with chunk option",
expected: {
data: [["H1", "H2", "H3"], ["d1", "d2", "d3"], ["d4", "d5", "d6"]],
errors: [],
meta: {
aborted: false,
cursor: 26,
delimiter: ",",
linebreak: "\n",
renamedHeaders: null,
truncated: false,
}
},
run: function(callback) {
Papa.parse('H1,H2,H3\nd1,d2,d3\nd4,d5,d6', {
worker: true,
chunk: function() {},
complete: function(results) {
callback(results);
}
});
}
},
];

describe('Custom Tests', function() {
Expand Down