I have below code, Where passing array length is too high and processing each array element taking one second of time, How i can use worker threads in below condition?
function processData(arr){
var result = [];
for(var i = 0; i < arr.length; i++){
result.push(process(arr[i]));
}
return result;
}
function process() {
// some code here takes 1 second to execute
}
processData(arr);
You can use
workerpool
npm package to do your long processing job in a worker thread, something like this