The for loop in js is executed many times, and there is a problem with the loop before exiting.

function aa () {
    (async () => {
      for (let i = 0; i < 10; iPP) {
        console.log(i, "iiiii")
        await new Promise((resolve1, reject1) => {
          (async () => {
            for (let j = 0; j < 20; jPP) {
              await new Promise((resolve, reject) => {
                setTimeout(() => {
                  resolve()
                }, 5000)
              })
              console.log(i, j)
            }
            resolve1()
          })(this)
        })
      }
    })(this)
}

execute aa () for five seconds before executing aa ()

the above two loops are executed when clicked. If I click 5 times, then for will execute the previous 4 times if it is not finished, in addition to executing the last click loop. Could you tell me how to skip the previous loop and directly execute it for the last time?

Mar.11,2022

var tmp = []
function aa (num) {
    (async () => {
      for (let i = 0; i < 10; iPP) {
        if (exist(num)) {
          break
        }
        console.log(num, 'ourter')
        await new Promise((resolve1, reject1) => {
          (async () => {
            for (let j = 0; j < 20; jPP) {
              if (exist(num)) {
                  break
              }
              console.log(num, 'inner')
              await new Promise((resolve, reject) => {
                setTimeout(() => {
                  if (!exist(num)) {
                    resolve()
                  }
                }, 5000)
              })
              console.log(i, j)
            }
            resolve1()
          })(this)
        })
      }
    })(this)
}
function exist (num) {
  if (num != tmp[tmp.length - 1]){
    return true
  }
  return false
}
tmp.push((tmp.length))
aa(tmp[tmp.length - 1])
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1ea21ec-47984.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1ea21ec-47984.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?