I have an array of items. I want to call an asynchroneous funcion on all of them. When the work is done for all items i want to call other function. I can not use any external libraries.
//array
var items;
for ( var i in items){
// function doAsync supports callback
items[i].doAsync(function callback(){...});
}
I have done it like this, but I am not sure if this is a safe solution:
var items;
var loopsFinished = 0;
for (var i in items) {
items[i].doAsync(function callback() {
...
loopsFinished++;
if (loopsFinished == items.length) {
otherFunction();
}
});
}