javascript - Async.ParallelLimit callback already called -


i using request module downloading reports.i using parallellimit method limit number of simultaneous tasks.

code iterate array is:

_.each(strs,function(str){     _.each(experiences,function(selectedexperience){           asynctasks.push(function(callback){             downloadreport(name,inp.btime,inp.etime,selectedexperience,callback);             });          });     }); }); 

code async task function is:

 var downloadreport = function(name,starttime,endtime,selectedexperience,callback){     request.post({                 headers: myheaders,                 uri: strurl,                 form: formobject,                 method: 'post'               }, function (err, res, body) {               if(err){            downloadreport(kpiname,starttime,endtime,selectedexperience,callback);                                   }                       else if(res)                       {                         if(body.indexof("some string")>=0){                               console.log("no records returned!!!");                                 callback(null,arr);                                              }                           else if(!(body.indexof("some string")>=0))                           {                                   var samp=body.substring(body.indexof("\n")+1);                              csv.fromstring(samp, {headers: true})                             .on("data",function(data){                             arr.push(data);                             })                             .on("end",function(){                                  console.log("array length:",arr.length);                                 callback(null,arr);                             });                           }                           else                           {                               //some code here                                 (i=0;i<a.length;i=i+2){                                     downloadreport(name,a[i],a[i+1],selectedexperience,callback);//calling same function                                 }                           }                       }                   });          } 

code async parallel limit

async.parallellimit(asynctasks,3,function(err, results){     if(err) console.log(err);     dosomething(); }); 

requirement invoke dosomething() once after async tasks executed.but getting following error:

 if (fn === null) throw new error("callback called.");                ^ 

how call callback once in situation?


Comments

Popular posts from this blog

Hatching array of circles in AutoCAD using c# -

ios - UITEXTFIELD InputView Uipicker not working in swift -

Python Pig Latin Translator -