timer_init {governor} | R Documentation |
Create a timer object which will return TRUE
when checked and the
given duration has elapsed.
Description
The timer will automatically reset any time it is checked (via check_timer()
)
and it returns TRUE
.
Usage
timer_init(duration, reset_mode = "checked")
Arguments
duration |
timer duration in seconds |
reset_mode |
one of 'checked' (default) or 'created' . If 'checked', then
when the timer is reset the next alarm will be set to |
Value
a timer
object to used with timer_check()
Examples
# Run two timers in a tight 'while' loop
# The short timer should trigger every 0.1 seconds
# The long timer will trigger after 1 second
# Note that the timers will reset every time they trigger (after returning TRUE)
long_timer <- timer_init(1)
short_timer <- timer_init(0.1)
counter <- 0L
while(TRUE) {
if (timer_check(long_timer)) {
cat("\nLong timer fired at count: ", counter, "\n")
break;
}
if (timer_check(short_timer)) {
cat("Short timer fired at count: ", counter, "\n")
}
counter <- counter + 1L
}
[Package governor version 0.1.2 Index]