Tabular IQ

Overview

The Timer class represents a timer for firing events at a specified interval.

Constructor

Timer()

Events

Timer.tick
Fired each time a timer interval has passed.

Methods

Timer.getInterval
Gets the timer event interval.
Timer.isRunning
Returns true if the timer is running and false otherwise.
Timer.setInterval
Set the timer event interval.
Timer.start
Starts the timer
Timer.stop
Stops the timer

Example

// 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();

Timer.getInterval

function Timer.getInterval() : Integer

Returns

The time interval in milliseconds at which the the timer tick event is to be fired.

Description

This function returns the time interval in milliseconds at which the timer tick event is to be fired.

Timer.isRunning

function Timer.isRunning() : Boolean

Returns

True if the timer is running and false otherwise.

Description

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.

Timer.setInterval

function Timer.setInterval(interval : Integer)

Arguments

interval
The time interval in milliseconds at which the the timer tick event is to be fired.

Description

This function sets the time interval in milliseconds at which the timer tick event is to be fired.

Timer.start

function Timer.start()

Description

This function starts the timer, so that the tick event is fired at a periodic interval.

Timer.stop

function Timer.stop()

Description

This function stops the timer, so that the tick event stops firing.

Timer.tick