I am writing a bot that sends alerts at variable intervals. I am using setTimeout () and I have a problem that I cannot understand. Code (simplified):
timeout = setTimeout(issueAlarm, 2147483647);
var nextD = dh.peekNext();
if (nextD.timestamp >= mom.valueOf() ){
var now = new Date();
clearTimeout(timeout);
timeout = mom.valueOf() - now;
setTimeout(issueAlarm, timeout);
}
function issueAlarm() {
var next = dh.getNext();
var peek = dh.peekNext();
if (peek) {
var now = new Date();
timeout = peek.timestamp - now;
setTimeout(issueAlarm, timeout);
}
}
As examples of input data: First input entered: set an alert every 8 hours, starting at 5 minutes (“Bob call”)
Second Input Introduced: Set an alert every 8 hours, starting at 4 minutes (“Jane Call”)
After 4 minutes, I correctly receive the “Jane call” (this set is installed from the bot code) After a minute, I correctly receive the “Bob call”, but also I receive the “Jane call” (which should not happen before 8 hours)
, . setTimeout() issueAlarm().
: _idleTimeout: 59994 ( , )
: _idleTimeout: 28739994 ( , 8 , )
: _idleTimeout: 28799991 ( - , )
botFramework. JavaScript node.js . , , , .
, , , . , .