Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Javascript node.js how do I parallel process For loops?

I only started to learn javascript 2 days ago so I'm pretty new. I've written code which is optimal but takes 20 minutes to run. I was wondering if there's a simple way to parallel process with for loops e.g.

for (x=0; x<5; x++){ processor 1 do ...

for (x=5; x<10; x++){ processor 2 do ...

like image 367
oa262 Avatar asked Mar 15 '23 01:03

oa262


1 Answers

Since the OP wants to process the loop in parallel, the async.each() function from the async library is the ideal way to go.

I've had faster execution times using async.each compared to forEach in nodejs.

like image 187
sampath Avatar answered Mar 25 '23 03:03

sampath