I have this loop for download some files and it's work fine.
But the files are downloaded like "2,3,4,1,5" order and not "1,2,3,4,5".
I know how to do .each async and waterfall async but I don't know how to do for this loop.
Config.TotalFiles = 5;
for(i = 1; i <= Config.TotalFiles; i++) {
$this.CreateJSONFile(i, function() {
cls();
});
}
And when downloads are done I want to call my callback, I have tried this if(id == Config.TotalFiles)
but it's doesn't work because the id isn't good.
How can I done an "async" process with this loop?
Thanks
async.times
? – Bergi Jul 25 '17 at 10:14CreatJSONFile
call does its job. They're started in the expected order always. If you want to ensure they also end in the expected order, your only choice is to do it sequentially instead of in parallel (using the…Series
methods). – Bergi Jul 25 '17 at 11:13