Say I have an array and a function A:
var array = ['a', 'b', 'c'];
function A(p) { ... };
now I want to pass each item of array to function A, and want them to be executed in a sequential order. usually there won't be any problem. I can do:
array.forEach(function(item) {
A(item);
}
however, if there are some asynchronous action in A, everything becomes messed up. so the question is:
How can I have them executed orderly even if there are asynchronous actions in A?
By which I mean, I want A('b') to be executed after A('a') is completely finished (including all the asynchronous actions in there).
I guess there must have been some utilities doing such things already. can someone shed me some light?
Aonly accept one param, and it has no ability to notify server when it complete its works(the callbacks), so the server can't decide whetherA('b')is complete or not.