我有一组 URL,我必须使用 JS / Cordova 异步函数下载它们。我当前的实现看起来像这样(简化):
var urls = [ ...... many many ...... ]
var arrayPointer = 0;
downloadData();
function downloadData() {
if(arrayPointer >= urls.length) {
do_something_else();
return false
}
downloadURL(urls[arrayPointer++],successDownloadCallback,failDownloadCallback);
return false;
}
function failDownloadCallback() {
logError();
downloadData();
return false;
}
function successDownloadCallback(data) {
saveDataToFile(data,saveSuccessCallback,saveFailCallback);
return false;
}
function saveFailCallback() {
logError();
downloadData();
return false;
}
function saveSuccessCallback() {
downloadData();
return false;
}
不幸的是,我有时会收到“超出最大调用堆栈大小”的错误。有一个更好的方法吗?
波斯汪
相关分类