5.4. Timers

There are three different methods for attaching a timer to an event-handling method or function: TimerAt, TimerAfter, and TimerEvery. They use the Gamma functions at, after, and every respectively. For example:

method Application.TimerEvery (seconds, fn)
{
    local    tid = every (seconds, fn);
    ._TimerIDs = cons (tid, ._TimerIDs);
    tid;
}

This is a wrapper on the Gamma every function. It creates a timer ID and adds it to the class's list of timer IDs (_TimerIDs). This way the timer can be identified and removed when necessary.

method Application.RemoveTimer(tid)
{
    if (find_equal (tid, ._TimerIDs))
    {
        cancel (tid);
        .droptimer (tid);
    }
}

This method uses the Gamma find_equal function to locate a timer according to its ID number (tid), and then uses the Gamma cancel function to cancel it.