ReferenceError: fn running on worker thread can't resolve Reference
For My example below:
var Parallel = require('paralleljs'); var _ = require('lodash');
let data = { "a":{"id":1}, "b":{"id":2}, "c":{"id":3}, "d":{"id":4} };
for(let i in data){
const p = new Parallel(data[i]);
p.spawn(test)
.then(function (data) {
console.log("iv",_.capitalize('hello'))
const documentProcessingData = ["DATA_MODEL_1","DATA_MODEL_2", "DATA_MODEL_3"];
documentProcessingData.forEach((curr,index)=>{
const aiProjectProcessing = new Parallel(curr);
aiProjectProcessing.spawn(dmdPrcosessing) .then(function (data) {
console.log("Finished", data);
})
})
});
}
function test(dmd){ console.log("hello",dmd); console.log("ii", .capitalize('hello')) //can't resolve "" lodash here return dmd }
function dmdPrcosessing(val){
console.log("iii", _.capitalize('hello')) //can't resolve "_" lodash here
var start = new Date().getTime();
var end = start;
var waitingTime = (Math.random() * (10000 - 5000) + 5000);
console.log("waitingTime ",waitingTime);
while(end < start + waitingTime){
end = new Date().getTime();
} return val; }
I get the following error:
undefined:3 console.log("ii", _.capitalize('hello')) ^
ReferenceError: _ is not defined
at dmdPrcosessing (eval at
Is there a better way to do this?