Async await polling timeout processing

there is a scenario where I need to use setInterval to obtain ajax requests (the backend is unwilling to use webscoket). I find that when the interface is in pending, it is still polling for sending requests. I want to make an optimization, that is, stop sending requests when the interface is pending, and then continue polling until the data is returned at the backend. Can this be solved with async and await?


function sendRequest() {
  return new Promise((resolve, reject) => {
    setTimeout(() => {
      resolve('receive response');
    }, Math.round(Math.random() * 2000));
  })
}

async function runTasks() {
  for (let i = 0; i < 1000; iPP) {
    const res = await sendRequest();
    console.log(res);
  }
}

runTasks();
This is what

should mean. Wait until the last request is completed and then send the next request. The network request is simulated with setTimeout .


you can set timeout for the ajax request, and resend the request after the timeout.

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-1bedb18-31b86.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-1bedb18-31b86.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?