Answer the question
In order to leave comments, you need to log in
"Eternal" process setInterval vs setTimeout?
The task is to periodically receive information from the remote api on the server with a certain time interval. The process itself will start with the server:
http.createServer(app).listen(PORT, function () {
runForrestRun();
});
function runForrestRun() {
shared.timeoutId = setTimeout(
function () {
console.log("Hello");
},
shared.timeout);
}
const shared = require('./shared');
const handler = require('./handler');
// start process
router.post('/api/start', function (request, response) {
runForrestRun();
handler.success(response, 'ok');
});
// stop process
router.post('/api/stop', function (request, response) {
clearTimeout(shared.timeoutId);
handler.success(response, 'ok');
});
// update timeout interval
router.post('/api/timeout', function (request, response) {
shared.timeout = request.body.timeout;
handler.success(response, 'ok');
});
// get current timeout interval
router.get('/api/timeout', function (request, response) {
handler.success(response, '', shared.timeout);
});
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question