I'm studying Nodejs and trying to run this script what loops a function. How to send the time variable to setInterval everytime after the break? In this example The first interval is 15000ms then, when the script continue running, will be changed according whether variable was met. After first and second "ifs", time needs to be 14000ms, then the script will loop again then meet the third and forth "ifs", changing the time to 15000ms again. Not sure if I was clear but here is the code.
let app = http.createServer((req, res) => {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Hi');
});
var time = 15000;
function grebData(time)
{
try{
if (something1){
var i=0;
while(true){
i++;
if(i===1){
if (something2){
time = 14000;
}
break;
}
}
setTimeout(grebData,time);
}
if (something3){
var i=0;
while(true){
i++;
if(i===1){
if (something4){
time = 15000;
}
break;
}
}
setTimeout(grebData,time);
}
}
catch (err) {
console.log(err);
process.stdin.resume();
}
};
setTimeout(grebData,time);
app.listen(3001,'0.0.0.0');