Wednesday, 24 May 2017

working on array with async.parallel

I was working with async module in Node.js , I am stuck in the problem of getting the order of values from global array in async.parallel module.

function(callback)
{
let array = [url,url,url,url,url,url,url,url,url,url];

async.parallel([
    function(cb){
        //working on one url from array and then remove from array
    },
    function(cb){
        //working on one url from array and then remove from array
    },
    function(cb){
        //working on one url from array and then remove from array
    },
    function(cb){
        //working on one url from array and then remove from array
    },
    function(cb){
        //working on one url from array and then remove from array
    }
],function(error,result){
    if(error)
        callback(error);
    else{
        callback(null,true);
    }   
})
}

Each internal functions of async.parallel will call request module to get another html page and after extracting its url links,then again inserting those url links to global array "array".

I am not getting how do we know which array element is used by which function ?



via Udit Kumawat

No comments:

Post a Comment