Increment
You can add a callback that grows:
for (var i = 0; i < len; i++) { asycFunction(someArray[i]); asycFunction.done = function () { if (i == someArray.length - 1) {
Recursive approach
This type of approach is preferred by some developers, but (possibly) takes longer because it is waiting for completion to start another.
var limit = someArray.length, i = 0; function do(i) { asyncFunction(someArray[i]); asyncFunction.done = function () [ if (i++ == someArray[i]) { // All done! } else { do(i); } } } do(i++);
Promises
Promises are not yet supported, but you can use the library. However, this will add a little to your page.
Good decision
(function (f,i) { do(i++,f) }(function (f,i) { asyncFunction(someArray[i]); asyncFunction.done = function () { if (i++ === someArray.length - 1) {
source share