javascript - How to execute a undefined number of funcA() and funcB() before starting funcC()? -


i have app writed in javascript. work, need download bunch of files. since can have lot of file wich can long, made download asynchronous:

function download_all(xml, callback){     var i=0;     while(i<xml.smil.length)     {         download(xml.smil[i]);         i=i+1;     }     i=0;     while(i<xml.video.length)     {         download(xml.video[i]);         i=i+1;     }     callback(xml); } 

my question is: download have callback, since there can 5 smil , 30 videos, how can make sure of download made before callback of download_all called?

i thougth of incrementing variable after each complete download (in callback) , like

while(smildlcompleted<xml.smil.length && videodlcompleted<xml.video.length) {     sleep(1000); } 

like have in c, can t find sleep function , seems opposite rigth syntax of js/node.js.

is there way wait download complete before callback?

i did have @ how execute javascript function after multiple other functions have completed?, since problem quite same (funca(), funcb(), , when done, funcc()), in case, funca() , funcb() can launched ten or twenty times before need funcc().

i m trying modify answer code of other question need, know easier way?

take @ async github library. can used in both node js , browser. either need async.parallel or async.series.


Comments

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

css - Firefox for ubuntu renders wrong colors -