class kitchen_timer
Counts a simulation time (not a wall clock time) and triggers an event once the timer expires. This class is not thread-safe.
| kitchen_timer | Counts a simulation time (not a wall clock time) and triggers an event once the timer expires. |
| Events | |
| ring | Triggers when the specified delay elapsed. |
| Functions | |
| new | Creates a new timer. |
| set_delay | Sets the delay for the timer to ring. |
| add_delay | Adds the specified delay. |
| set_random_delay | Set the random delay for the timer to ring between the specified range. |
| start | Starts the timer. |
| stop | Stops the timer. |
| pause | Pauses the timer. |
| resume | Resumes the timer, if the timer was paused. |
| reset | Resets the timer. |
| get_elapsed | Returns the elapsed time since the timer was last started or resumed. |
| get_remaining | Returns the remaining time to ring. |
| is_stopped | Returns 1 if the timer is currently stopped. |
| is_running | Returns 1 if the timer is currently running. |
| is_paused | Returns 1 if the timer is currently paused. |
| get_state | Returns the current state of the timer. |
function time set_random_delay( time delay1, time delay2 )
Set the random delay for the timer to ring between the specified range. This function resets the timer.
| delay1 | The delay boundary 1. |
| delay2 | The delay boundary 2. The delay is randomized between delay1 and delay2, inclusive. |
The randomized delay value.
kitchen_timer kt = new(); time random_delay = kt.set_random_delay( 100, 200 ); kt.start(); @kt.ring; assert( kt.get_elapsed() == random_delay );
function void start()
Starts the timer. The ring event is triggered when the remaining time becomes 0. The timer can be stopped by calling stop or be paused by calling pause. If the timer is already started, no action is taken.
kitchen_timer kt = new(); kt.set_delay( 100 ); kt.start(); @kt.ring; assert( kt.get_elapsed() == 100 );
function void pause()
Pauses the timer. The elapsed time is stamped if the timer was running. The timer can be resumed by calling resume. If the timer was not running, no action is taken.
kitchen_timer kt = new(); kt.set_delay( 100 ); kt.start(); #50 kt.pause(); assert( kt.get_elapsed() == 50 );
function time get_elapsed()
Returns the elapsed time since the timer was last started or resumed. If the timer is paused or stopped, returns the elapsed time to the last paused or stopped time.
The elapsed time.
kitchen_timer kt = new(); kt.set_delay( 100 ); kt.start(); @kt.ring; assert( kt.get_elapsed() == 100 );
function time get_remaining()
Returns the remaining time to ring. If the timer is paused or stopped, returns the remaining time from the last paused or stopped time.
The remaining time.
kitchen_timer kt = new(); kt.set_delay( 100 ); kt.start(); #30; assert( kt.get_remaining() == 70 ); @kt.ring; assert( kt.get_remaining() == 0 );
function bit is_paused()
Returns 1 if the timer is currently paused.
If the timer is currently paused, returns 1. Otherwise, returns 0.
kitchen_timer kt = new(); kt.set_delay( 100 ); kt.start(); #50 kt.pause(); assert( kt.is_paused() == 1 ); kt.resume(); #10; assert( kt.is_paused() == 0 );
function state_e get_state()
Returns the current state of the timer.
The current state of the timer.
kitchen_timer kt = new(); kt.set_delay( 100 ); kt.start(); #50 kt.pause(); assert( kt.get_state() == kitchen_timer::PAUSED ); kt.resume(); #10; assert( kt.get_state() == kitchen_timer::RUNNING );
Counts a simulation time (not a wall clock time) and triggers an event once the timer expires.
class kitchen_timer
Creates a new timer.
function new( time delay = 0 )
Sets the delay for the timer to ring.
function void set_delay( time delay )
Adds the specified delay.
function void add_delay( time delay )
Set the random delay for the timer to ring between the specified range.
function time set_random_delay( time delay1, time delay2 )
Starts the timer.
function void start()
Stops the timer.
function void stop()
Pauses the timer.
function void pause()
Resumes the timer, if the timer was paused.
function void resume()
Resets the timer.
function void reset()
Returns the elapsed time since the timer was last started or resumed.
function time get_elapsed()
Returns the remaining time to ring.
function time get_remaining()
Returns 1 if the timer is currently stopped.
function bit is_stopped()
Returns 1 if the timer is currently running.
function bit is_running()
Returns 1 if the timer is currently paused.
function bit is_paused()
Returns the current state of the timer.
function state_e get_state()