
Event Timer
loop.thread.Timer
Class of objects that triggers a function continuously in a regular rate. It also avoids accumulation of triggering events if the function execution overlaps the time of the next event. In such case, the overlapped event is canceled. This class is useful to implement monitors that are executed from time to time in a cooperative multi-threaded application.
Each instance is bounded to an instance of Scheduler
which is used to register a thread that executes continuously the triggered function and sleeps until the time for the next execution. It also measures the time the function execution lasted in order to avoid accumulation of delayed execution.
Behavior
Initialization
Timer([object])
- Makes
object
an instance ofTimer
. It also creates the thread that continously executes the defined action. If noobject
is provided, a new table is created to represent the new instance.
Fields
action
- Function called at each triggering event.
enabled
- Boolean value that indicates if the timer is enabled or not. This field should not be changed by the application. To do so, use the methods
enable
anddisable
. rate
- Time rate, in seconds, that the function
action
should be executed. scheduler
- Object that implements the API of
Scheduler
and is used to register the thread that executes the timer. thread
- Co-routine that implements the thread that executes the timer. This thread is registered in the object of field
scheduler
when the timer is enabled.
Methods
timer()
- Method that implements the timer behavior. This is the function executed by the timer thread.
enable()
- Method that enables the execution of the timer to start triggering the defined action.
disable()
- Method that disables the execution of the timer preventing that the action be executed again.
Remarks
- The time precision of the timer depends on the precision provided by object of field
scheduler
.
Examples
$ExampleDescription
-- example missing
Copyright (C) 2004-2008 Tecgraf, PUC-RioThis project is currently being maintained by Tecgraf at PUC-Rio.