Runtime keeps track of time to control how long a tool’s main loop runs. This package was created to handle mk-query-digest --run-time-mode event. In essence, we abstract time so that the tool doesn’t know/care whether now() comes from a clock, a log timestamp, or wherever. The creator of Runtime object determines how, or from where, time is gotten so that the caller of the object can simply ask, “What time is it?”.
Runtime | Runtime keeps track of time to control how long a tool’s main loop runs. |
Functions | |
new | |
time_left | Return the number of runtime seconds left or undef for forever. |
have_time | Return true or false if there’s runtime left. |
time_elapsed | How much time has elapsed since time_left() was first called. |
reset | Reset this Runtime object for another run. |
stop | Stop the coutdown, make time_left() return 0 and have_time() false. |
start | Restart the countdown after having called stop(). |
_d |
sub time_left
Return the number of runtime seconds left or undef for forever. The return may be less than zero if the runtime has been exceeded. The first call to this subroutine “starts the clock”, so to speak, if the now callbackup returns a defined value.
%args | Arguments passed to now callback. |
Number of runtime seconds left, possibly less than zero, or undef if running forever.
sub have_time
Return true or false if there’s runtime left. This sub is a simpler wrapper around time_left() which returns true (1) if time left is defined and greater than zero or undef, else returns false.
%args | Arguments passed to now callback. |
True if time left is defined and greater than zero or undef, else false.
sub time_elapsed
How much time has elapsed since time_left() was first called.
%args | Arguments passed to now callback. |
Number of seconds elapsed since time_left() was first called.
sub reset
Reset this Runtime object for another run. If you want to re-use this object (e.g. for another iteration of the tool’s main loop), call this sub to reset the internally saved times for time_left() and have_time().
sub stop
Stop the coutdown, make time_left() return 0 and have_time() false. After calling this sub, you must call start() or reset() to recommence the countdown.
sub new
Return the number of runtime seconds left or undef for forever.
sub time_left
Return true or false if there’s runtime left.
sub have_time
How much time has elapsed since time_left() was first called.
sub time_elapsed
Reset this Runtime object for another run.
sub reset
Stop the coutdown, make time_left() return 0 and have_time() false.
sub stop
Restart the countdown after having called stop().
sub start
sub _d