javascript - NodeJs Use async with for loop download -


i have loop download files , it's work fine.

but files downloaded "2,3,4,1,5" order , not "1,2,3,4,5".

i know how .each async , waterfall async don't know how loop.

config.totalfiles = 5;  for(i = 1; <= config.totalfiles; i++) {    $this.createjsonfile(i, function() {      cls();    }); } 

and when downloads done want call callback, have tried if(id == config.totalfiles) it's doesn't work because id isn't good.

how can done "async" process loop?

thanks

you can use async.whilst this:

config.totalfiles = 5; var count = 1;  //pass maincallback want call after downloading of files complete.  var callme = function(maincallback){     async.whilst(         function() { return count <= config.totalfiles; },         function(callback){             $this.createjsonfile(count, function() {                 cls();                 count++;                 callback();             });         }, function(){            //this function final callback            maincallback();         }) } 

Comments

Popular posts from this blog

networking - Vagrant-provisioned VirtualBox VM is not reachable from Ubuntu host -

c# - ASP.NET Core - There is already an object named 'AspNetRoles' in the database -

ruby on rails - ArgumentError: Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true -