The Timer class allows you to execute code at specified intervals. Its
precision is platform-dependent, but in general will not be better than 1ms nor
worse than 1s.
There are several different ways to use this class:
The most convenient way is to use the Timer.every class method, which accepts
a Integer to specify the millisecond interval at which the Timer should
fire, and a block to specify what should happen at that interval. For
example, to print a message to STDOUT every 1/2 second:
Secondly you may use the event handling mechanism to direct events to
any object which inherits from EvtHandler. To do this
use the longer constructor or set_owner. Then use the
evt_timer
method to connect it to the event handler which will receive
TimerEvent notifications.
Lastly, you may derive a new class from Timer and define your own
notify instance method in that to perform the
required action. For example:
Unless you use Timer.every, you must start the timer with start
after constructing it before it actually starts sending notifications. It can
be stopped later with stop
::StartTimer, ::GetElapsedTime, StopWatch
Creates a timer and associates it with owner_. Please see
set_ownersetowner for the description of parameters.
Carries out the action specified in the passed block after interval
milliseconds have passed. Note that the action will happen only once; if
you want a repeating action, use Timer.every
If you wish to interrupt the timed event before it may have happened,
capture the return value which is the newly created timer for this
action, and call stop on it.
Repeats the action specified in the passed block every interval
milliseconds. The timer is owned by the application object and will fire
as long as the application is running.
The method returns the new timer; if you may wish to stop the timer
before the application finishes, you should capture this return value so
you can call stop on it later.
Returns the id of the timer.
Returns the current interval for the timer (in milliseconds).
Returns true
if the timer is one shot, i.e. if it will stop after firing the
first notification automatically.
Returns true
if the timer is running, false
if it is stopped.
This member should be overridden by the user if the default constructor was
used and set_owner wasn’t called.
Perform whatever action which is to be taken periodically here.
Associates the timer with the given owner\/ object. When the timer is
running, the owner will receive timer events with
id equal to id\/ specified here.
false
)
(Re)starts the timer. If milliseconds\/ parameter is -1 (value by default),
the previous value is used. Returns false
if the timer could not be started,
true
otherwise (in MS Windows timers are a limited resource).
If oneShot\/ is false
(the default), the Notify
function will be called repeatedly until the timer is stopped. If true
,
it will be called only once and the timer will stop automatically. To make your
code more readable you may also use the following symbolic constants:
TIMER_CONTINUOUS | Start a normal, continuously running, timer |
TIMER_ONE_SHOT | Start a one shot timer |
If the timer was already running, it will be stopped by this method before
restarting it.
Stops the timer.
[This page automatically generated from the Textile source at 2023-06-09 00:45:31 +0000]