I have query in async.parallel module in nodeJS

57 views Asked by At

I'm trying to use async node module for my project I need it in huge way. when I tried follow code than it's not working. Please any one help me to figure out issue.

async.parallel({
   test : function(callback) {
       for(var i=0; i<1000000000; i++){
           if(i == 999999999){
               console.log("test");
               callback(null, "test");
           }
       }
   },
   test1 : function(callback) {
       console.log("test1")
       callback(null, "test1");
   }
}, function(err, results) {
    // optional callback
    console.log('results', results)
});

How these code would be execute ? I tried it's print { test: 'test', test1: 'test1' } but as per logically if parallel process executed than need output like { test1: 'test1', test: 'test' }.

If I use timeout insted of for loop than it's working fine.

1

There are 1 answers

0
Denis Lisitskiy On BEST ANSWER

this from async doc

Note: parallel is about kicking-off I/O tasks in parallel, not about parallel execution of code. If your tasks do not use any timers or perform any I/O, they will actually be executed in series. Any synchronous setup sections for each task will happen one after the other. JavaScript remains single-threaded.

So, youre For loop is do task in sync way