The Timer class represents a timer for firing events at a specified interval.
// define our timer class
class MyTimer {
// total amount of time that has elapsed since the timer started
time_total = 0;
// the interval in milliseconds at which the timer event fires
time_interval = 100;
timer = null;
constructor() {
// create a new timer object, set it to fire the tick event at
// the specified interval, and connect the tick event to the
// onTick method
this.timer = new Timer();
this.timer.setInterval(this.time_interval);
this.timer.tick.connect(this, this.onTick);
// start the timer
this.timer.start();
}
onTick() {
// onTick will be called every time the specified interval has
// elapsed, which in this case is 100 milliseconds
// track the total time since the event started firing
this.time_total += this.time_interval;
// if 1 second has elapsed, stop the timer
// and issue an alert
if (this.time_total >= 1000) {
this.timer.stop();
alert("1 second has elapsed");
}
}
}
// create a new instance of our timer class
// and start the application event loop
const t = new MyTimer();
Application.run(); The time interval in milliseconds at which the the timer tick event is to be fired.
This function returns the time interval in milliseconds at which the timer tick event is to be fired.
True if the timer is running and false otherwise.
This function indicates whether or not the timer is currently running, and therefore, firing timer events. Returns true if the timer is running and false otherwise.
This function sets the time interval in milliseconds at which the timer tick event is to be fired.
This function starts the timer, so that the tick event is fired at a periodic interval.
This function stops the timer, so that the tick event stops firing.