How to ensure all the async calls are back in javascript -


i have piece of javascript code doing

function asyncs(){     var backcount = 0;     function done(){         if(backcount === 2){             alert("all done");             dosomthinguseful();         }else{             backcount ++;         }     }     function asynccall(callback){         myremotecall(callback);     }     asynccall(done);     asynccall(done);     asynccall(done); }  function dosomethinguseful(){     alert("travel moon.") } 

this working. wondering if there better approach don't have write ugly counter function.

i recommend using flow control library async or nimble handle sort of thing. internally pretty same thing gives them in reusable patterns.


Comments

Popular posts from this blog

All overlapping substrings matching a java regex -

c++ - Using OpenSSL in a multi-threaded application -

php - Deleting/Renaming a locked file -