running async with two tasks using nodejs?

I wanted to be able to run two tasks inside async each function using the "async module".

for example:

async.each(openFiles, function( file, callback) {
    // task 1
    function(){
          callback();
     } 

    function(){
          callback(); // task 2, waits for task 1 to finish 
     }  
}, function(err){
   console.log("done");
});

Im using each because Im looping through each value and need apply two asks to each element.

You should be able to run async.series inside async.each. This will iterate openfiles and run the series inside, it will only then progress through the each loop when series has finished.

async.each(openFiles, function(file, eachCallback) {
    async.series([

        function(seriesCallback) {
            seriesCallback();
        },
        function(seriesCallback) {
            seriesCallback();
        }
    ], function() {
        eachCallback();
    })
}, function(err) {
    console.log("done");
});

Here is some code for the 2-async approach:

async.each(openFiles, function( file, callback) {

 async.each([task1, task2], function(task, cb) {

  task(file); // exec tasks 1, 2
  cb();       // one completed

 }, callback); // both completed

}, function(err){
 console.log("done");
});

You can make use of javascript callback over here to create dependency of task1 on task2. Something like this:

async.each(openFiles, function( file, callback) {
    // task 1
    function task1(function(){
          function task2 (function(){
              //callback of async
              callback();
          });
     }); 
}, function(err){
   console.log("done");
});

and your task 1 and task 2 function will take the callback as an argument something like this:

function task1(callback){
    //do whatever in task1
    callback();
}

function task2(callback){
    //do whatever in task1
    callback();
}

In this way task2 will run only when task1 is complete inside async.each