所以基本上我有一个带有异步函数的for循环.问题是程序在循环之后才继续,我希望它等到循环中调用的所有异步函数在代码继续之前完成.
在我的代码中,"bar"是一个json数组,其中包含其他json数组.
function write(bla) { // gets called one after another
for(var url in bla) {
asyncFunctionCall(url); // Executed about 50 times, it has to run parallel
}
// Wait for all called functions to finish before next stuff happens and
// write gets called again.
}
for(var foo in bar) {
// Here i parse the json array "foo" which is in the json array "bar"
write(foo[bla]); // bla is an array of multiple urls.
}
Run Code Online (Sandbox Code Playgroud)
异步函数调用看起来像这样:
var request …Run Code Online (Sandbox Code Playgroud)