Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

134
Visualizações
Javascript - How to execute a function on a given time ? (with variable time periods)

I have to make a request to the backend server to retrieve some data, and inside the response comes the hour of the day that I have to make the request again. For example: I make the request at 12:00 am, and the response comes with the data I need, and also the next time I have to make the request again, for example "16:00".

This 'loop' will never end as long as the application is running. The thing is, my code works, but I dont know whether it is a good practice, because I call the same function over and over again.
Can someone explain to me if it's okay what I'm doing?

This is my code so far:

aFunction() {
  this.programacionService.getNextData().subscribe((r: any) => {
    console.log(r);

    window.setTimeout(() => {

        // Programming logic

        // Repeat the process
        this.aFunction.call(this);
      },
      // This is a method to format the hour of the day
      this.functionTimeout(r.hourToMakeTheRequestAgain)
    );
  })
}

Is this correct? Won't it make the 'callStack' overflow over time? Thanks in advance!

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

I don't know if this is true but : as long as your request would not take a lot of work from the server, you'll be fine.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda