Javascript中承诺的顺序处理

时间:2018-06-13 15:05:36

标签: javascript promise

我的程序有以下结构:

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没有按顺序处理。

我怎样才能做到这一点?

0 个答案:

没有答案