Hello I am having problems with my setInterval
it is only executing only once the if
else
checks below is my function
const redis = require('redis');
const cache = redis.createClient();
require('./execSocket');
function teste(){
cache.dbsize(function(err,res){
if(res){
console.log(res);
if(res > 10){
require('./execSql');
}else{
require('./execSocket');
}
}else{
console.log(err);
require('./execSocket');
}
});
}
setInterval(function(){
teste();
},20000);
when I run the code, in the first run of setInterval it does the normal checks, but in the second run of setInterval it only gives me the number of records saved in bd and does not check if
else
2
Answers
I found this way to solve my problem, the code looks like this:
it's basically solving my problem !
require()
loads a module once and then retrieves it from cache and does not executes any code that is located inside the module without executing any function explicitly.Suggest exporting a dedicated methods from every method and execute them explicitly in your branches.
See require for more details.