1.171 class timer

A timer is an object that -when the system is dispatching messages- generates an event at regular intervals. Timers are used to implement simulation, blinking (caret) or to wake-up the user under some (time-based) conditions.

The interval of a timer is specified as a real-number. The actual accuracy depends on the timing capabilities offered by the X-implementation on which PCE has been build.

When executing the message, no arguments are forwarded. @receiver is bound to the timer itself. See timer->execute.

NOTE: When multiple objects are animated at a similar speed performance will be much better if a single timer is used. The code below provides a skeleton:

:- pce_global(@stepping, chain).

start_stepping :-
        send(new(@stepper,
                         timer(1, message(@stepper, for_all,
                                                          step))),
             start).

step(Obj) :-
        send(@stepping, append, Obj).
See also
class date

1.171.1 Instance variables

timer <- interval: real
Interval in seconds. Note that

timer <-> message: code*
Code executed each time. See timer->execute for details.
timer <-> service: bool
If @on, execution cannot be debugged. See also application->kind.
timer <- status: {idle,repeat,once}
Status of the timer. Its values:
idleTimer is not running
onceAfter timer->execute’ing once it will stop
repeatTimer will repeat timer->execute’ing

1.171.2 Send methods

timer ->delay:
Delay for timer<-interval. XPCE processes events while execution is suspended.
timer ->execute:
Execute the timers timer<-message with the following arguments:
@receiver		The timer itself.
timer ->initialise: interval=real, message=[code]*
Create a timer object from its interval and the message to execute. After creation, the timer is idle. Use timer->start or timer->status to start the timer.
timer ->start: how=[{repeat,once}]
Equivalent to timer->status: [repeat].
timer ->stop:
Equivalent to timer->status: idle.
timer ->running: running=bool
Start/stop the timer in repeat mode.
@on, timer->start is equivalent to timer->status: repeat
@off, timer->stop is equivalent to timer->status: idle.