我的程序有以下结构:
functionA(parentItemList){
// break parentItemList in multiple itemList and process one by one
const callBatchUpdate = function (index) {
try {
Promise.(functionB(itemList)).then(function () {
counter = counter + 1;
if (next itemlist is available) {
callBatchUpdate(counter);
} else {
console.log('Processing done');
}
}).catch(function(error) {
console.log("Counter:"+counter);
counter = counter + 1;
console.error(error);
if (chunkedIds[counter]) {
callBatchUpdate(counter);
} else {
console.log('Update done');
}
})
}catch(e){
}
}
callBatchUpdate(counter);
}
functionB(itemList){
return Promise(){
//process individual items in list one by one
}
}
我的目标是只有当functionB完全处理了itemList时,才会将functionNeList发送给functionB。 我在functionB中的适当位置调用了resolve()。但我仍然看到itemLists没有按顺序处理。
我怎样才能做到这一点?