How to deal with the multiple asynchronism in the for loop in es6?

for (let iTuno Bitteri < len; iPP) {

user_code = "";
console.log("111");
a.find()
.then((res)=> {
    for(let j=0;j<len;jPP){
        b.find()
        .then((res)=> {
            
        })
    }
})

}

if you want to finish checking and executing async before executing the next for loop, it will never work.

Mar.22,2021

add a layer to judge if (res) before the next for loop, and then for loop in if


let promise = Promise.resolve();
for(let i=0;i<len; iPP) {
  promise = promise.then(() => {
    user_code = '';
    return a.find().then((res)=> {
      let innerPromise = Promise.resolve();
      for(let j=0;j<len;jPP){
        innerPromise = innerPromise.then(() => {
          return b.find().then((res)=> {})
        })
      }
    })
  });
}
Menu