Execute three functions in the same setInterval

0

How can I perform three functions within the same setInterval, and for one the time to update should be different.

I've tried the following:

function sleep(ms) {
  return new Promise(resolve => setInterval(resolve, ms));
}
async function update() {
  for($i=0;$i<300;$i++){ // a cada 300x (5min) faz um refresh
      atualizaLeilao();
      atualizaLeilaoCancelado();
      updateClock();
      await sleep(1000);
  }
 location.reload(); 
}

$(document).ready(function () {
    update();
});

I need the atualizaLeilaoCancelado(); function to refresh every 5 minutes, not every second.

    
asked by anonymous 02.03.2018 / 13:43

1 answer

1

To execute atualizaLeilaoCancelado() every 5 minutes the simplest is to individualize this call in a setInterval to the part with its interval value:

function updateLeilaoCancelado(){
    setInterval(function(){
        atualizaLeilaoCancelado();
    }, 300000);
}

And then call both in the main code:

$(document).ready(function () {
    update();
    updateLeilaoCancelado();
});

I also advise you to review a bit of logic because if in%% of% after 300 iterations of update , which is 5 minutes refresh the page, then updating every 5 minutes loses its meaning.

    
02.03.2018 / 15:46