I was able to configure all in papa parser and it works well even with 200k items parsing. So I can process all the data and them await for each row in the result array. the problem is if I am using a step how I can make the step await the previous step? This is causing the parser to fires thousands of calls and then blocking me. I tried to wrapped the step in another function but that did not help either.
here is a sample of what I am doing in the step call
async function stepFn(results, parser) {
stepped++;
(await (async function () {
if (results) {
if (results.data) {
rowCount += results.data.length;
console.log('checking if item exists');
var itemExistsP = await restcallToRetrieve();
if (itemExistsP.length > 0) {
console.log('Item exists, skipping');
//return;
} else {
console.log('adding item to list');
await restcalltoAdd();
// return item;
}
}
if (results.errors) {
errorCount += results.errors.length;
firstError = firstError || results.errors[0];
}
}
}()));
}
Here is the Parser call:
Papa.parse($('#parse-file')[0].files[0], {
delimiter: '',
header: true,
dynamicTyping: false,
skipEmptyLines: true,
preview: 0,
encoding: '',
step: stepFn,
worker: false,
comments: '',
download: false,
complete: completeFn,
error: errorFn,
});
Just create an
async
stepFunction:Then in the
parse config object
:It would also be good to put everything you await in a
try catch
block but that's of course beside the point.