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

218
Visualizações
setInterval() doesn't work if a forever loop exists

Overview: (Skip if you want) I have basic knowledge of Javascript, I usually use javascript using node.js to code discord bots. As discord users know, discord already has bots for almost EVERYTHING. I needed some special ideas so I just decided to play around some javascript features and frameworks, hoping to get some ideas from it.

Problem: I discovered a function called setInterval(function, time), I was testing / playing with this function until I discovered something, here is my code:

console.log(`Starting interval with id: ${setInterval(() => {
    console.log(`I at this time is ${i}`)
}, [500])}`);

let i = 0;
for(;;++i);

I was expecting this to work but sadly it didn't. The variable i successfully gets incremented but the callback of setInterval() is never called.

My theory is that the processor is busy due to the high speed of the for(;;++i) so the callback doesn't get time to execute.

I tried to search about this on google, but I didn't know what to search, I even tried searching it on stack overflow but couldn't find anything.

I dont't know if this is a real question, neither do I know if this has a fix, but could someone at least tell me why this problem is occuring, am I right with my theory above?

about 4 years ago · Juan Pablo Isaza
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