Runtime

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?”.

Summary
RuntimeRuntime keeps track of time to control how long a tool’s main loop runs.
Functions
new
time_leftReturn the number of runtime seconds left or undef for forever.
have_timeReturn true or false if there’s runtime left.
time_elapsedHow much time has elapsed since time_left() was first called.
resetReset this Runtime object for another run.
stopStop the coutdown, make time_left() return 0 and have_time() false.
startRestart the countdown after having called stop().
_d

Functions

new

sub new

Parameters

%argsArguments

Required Arguments

nowCallback that sets current time.
runtimeAmount of time to run in seconds, or undef for forever.

Returns

Runtime object

time_left

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.

Parameters

%argsArguments passed to now callback.

Returns

Number of runtime seconds left, possibly less than zero, or undef if running forever.

have_time

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.

Parameters

%argsArguments passed to now callback.

Returns

True if time left is defined and greater than zero or undef, else false.

time_elapsed

sub time_elapsed

How much time has elapsed since time_left() was first called.

Parameters

%argsArguments passed to now callback.

Returns

Number of seconds elapsed since time_left() was first called.

reset

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().

stop

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.

start

sub start

Restart the countdown after having called stop().  Calling this sub has no affect unless stop() was called first.

_d

sub _d
sub new
sub time_left
Return the number of runtime seconds left or undef for forever.
sub have_time
Return true or false if there’s runtime left.
sub time_elapsed
How much time has elapsed since time_left() was first called.
sub reset
Reset this Runtime object for another run.
sub stop
Stop the coutdown, make time_left() return 0 and have_time() false.
sub start
Restart the countdown after having called stop().
sub _d
Close