| Allegro CL version 10.0 Unrevised from 9.0 to 10.0. 9.0 version |
A timer can be used to cause an arbitrary piece of application code to be asynchronously invoked after a specified amount of time has elapsed. A timer can then be stopped in order to run its code a single time only, or it can be allowed to continue running in order to run its code an indefinite number of times at a regular time interval.
Common Graphics has a timer
class, which can
be instantiated to create a timer object. A single timer can be
started and stopped a number of times, using various time intervals,
to time a number of different activities. If multiple activities need
to be timed simultaneously, then multiple timers can be created and
run alongside each other. It is also convenient to create a separate
timer for each piece of code that is to be invoked by timers, even
when they do not need to run simultaneously.
A timer is an instance of the timer
class, which has
the following properties. All of these except for id may be set by an
application. See the page for the timer
class or for the
individual properties for more detailed information.
An on-timer function may call stop-timer on the timer (or set the timer's active property to nil) if the on-timer function should be invoked only a single time after the timer is started. Otherwise the on-timer function will be called each time the timer's interval has elapsed until stop-timer is called on the timer (or its active property is set to nil).
When a timer is started, this property is set to zero. Each time a timer's interval has elapsed, the default timer method increments the timer's timer-count by one and then calls its on-timer function. If a timer count reaches 50 million, it is reset to zero to prevent the consing of bignums.
(The timer
class can of course be subclassed in order to add custom slots for
this or any other purpose, but this single timer-info slot is provided
since such a handy place is often needed due to the asynchronous
nature of timers, and a single slot is often sufficient.)
find-timer
start-timer
stop-timer
timer
On the GTK platform you might need to adjust the value of *cg-timer-resolution*
.
;; Define an on-timer event handler (defun my-on-timer (timer) ;; Show a status bar message each time the timer fires. (lisp-message "Timer event ~a for ~s" (timer-count timer)(name timer))) ;; Create a timer that uses the above on-timer event-handler. (setq tim (make-instance 'timer :on-timer 'my-on-timer)) (active tim) ==> nil ;; the new timer is not active yet ;; Start the timer, telling it to fire every half second (start-timer tim :interval 500) (active tim) ==> t ;; now it's active (stop-timer tim) ;; stop it for a while (setf (active tim) t) ;; this is another way to start it back up (setf (interval tim) 800) ;; slow it down even while it's running (setf (active tim) nil) ;; another way to stop it
Copyright (c) 1998-2019, Franz Inc. Oakland, CA., USA. All rights reserved.
This page was not revised from the 9.0 page.
Created 2015.5.21.
| Allegro CL version 10.0 Unrevised from 9.0 to 10.0. 9.0 version |