use IO::Async::Timer::Periodic; use IO::Async::Loop; my $loop = IO::Async::Loop->new; my $timer = IO::Async::Timer::Periodic->new( interval => 60, on_tick => sub { print "You've had a minute\n"; }, ); $timer->start; $loop->add( $timer ); $loop->run;
For a "Timer" object that only runs a callback once, after a given delay, see instead IO::Async::Timer::Countdown. A Countdown timer can also be used to create repeating events that fire at a fixed delay after the previous event has finished processing. See als the examples in "IO::Async::Timer::Countdown".
Even if this value is zero, the first invocation will be made asynchronously, by the containing "Loop" object, and not synchronously by the "start" method itself.
"hard" schedules each iteration at the fixed interval from the previous iteration's schedule time, ensuring a regular repeating event.
"skip" schedules similarly to "hard", but skips over times that have already passed. This matters if the duration is particularly short and there's a possibility that times may be missed, or if the entire process is stopped and resumed by "SIGSTOP" or similar.
"drift" schedules each iteration at the fixed interval from the time that the previous iteration's event handler returns. This allows it to slowly drift over time and become desynchronised with other events of the same interval or multiples/fractions of it.
Once constructed, the timer object will need to be added to the "Loop" before it will work. It will also need to be started by the "start" method.