timer.js | |
---|---|
Sends messages on interval or timeout. | var toddick = require('./toddick'); |
Toddick: IntervalRepeatdly sends a message on an interval.
delay - Number of milliseconds to delay before sending each message. MSG - The messsage to send. | toddick( 'Interval', module,
{
|
Message: INITInitializes the toddick with the constructor arguments. | INIT: function(delay, MSG) {
this.monitor(MSG.toddick);
this.interval_id = setInterval(
function() {
MSG();
},
delay
);
},
|
Message: EXITCancels the interval timer and exits. | EXIT: function(reason) {
clearInterval(this.interval_id);
this.exit(reason);
}
}
); |
Toddick: TimeoutSends a single message after a delay.
delay - Number of milliseconds to delay before sending the message. msg - The message to send. args - An array of arguments to send with the message. | toddick( 'Timeout', module,
{
|
Message: timeout.initInitializes the toddick using the constructor arguments. | init: function(delay, MSG) {
this.monitor(MSG.toddick);
this.timeout_id = setTimeout(
function() {
MSG();
this.timeout_id = undefined;
this.exit();
},
delay
);
},
|
Message: timeout.exitCancels the timeout timer and exits. | exit: function(reason) {
if(this.timeout_id) {
clearTimeout(this.timeout_id);
}
this.exit(reason);
}
}
);
|