Correct way to write loops for promise.

后端 未结 13 1877
猫巷女王i
猫巷女王i 2020-11-22 15:20

How to correctly construct a loop to make sure the following promise call and the chained logger.log(res) runs synchronously through iterat

13条回答
  •  眼角桃花
    2020-11-22 15:50

    First take array of promises(promise array) and after resolve these promise array using Promise.all(promisearray).

    var arry=['raju','ram','abdul','kruthika'];
    
    var promiseArry=[];
    for(var i=0;i {
        console.log(result);
      })
      .catch((error) => {
         console.log(error);
      });
    
    function dbFetchFun(name) {
      // we need to return a  promise
      return db.find({name:name}); // any db operation we can write hear
    }
    

提交回复
热议问题