How do I stop running a setInterval
that is running on a module that I do not need anymore? I'm not talking about just getting the setInterval
return and executing a clearInterval
. That's not it ...
Example:
app.js
// Rota de data e hora para uma página que exibe em tempo real essa informações para o usuário
const dateTimeSystem = require('./routes/date-time');
// outros códigos
app.use('/datetime' , dateTimeSystem);
date-time.js
// meus códigos...
//...
//..
setInterval(atualizaDataHora, 1000);
function atualizaDataHora() {
// meus outros códigos...
}
When I access the route to the date time page, this continuous update is correct and can go on indefinitely while I'm on the page. However, when going to any other route / page, I need this function to "UpdateDataTime" no longer run one at a time because I do not need it anymore. I checked in debug mode that it continues to run even after I switch to another page.
How do I stop setInterval
in this case?