| IO::Async::Timer - event callback after some timed delay |
IO::Async::Timer - event callback after some timed delay
use IO::Async::Timer;
use IO::Async::Loop; my $loop = IO::Async::Loop->new();
my $timer = IO::Async::Timer->new(
mode => "countdown",
delay => 10,
on_expire => sub {
print "Sorry, your time's up\n";
$loop->loop_stop;
},
);
$loop->add( $timer );
$loop->loop_forever;
This module provides a class of IO::Async::Notifier for implementing timed
delays. A Timer object implements a countdown timer, which invokes its
callback after the given period from when it was started. After it has expired
the Timer may be started again, when it will wait the same period then invoke
the callback again. A timer that is currently running may be stopped or reset.
The following named parameters may be passed to new or configure:
The type of timer to create. Currently the only allowed mode is countdown
but more types may be added in the future. Can only be given at construction
time.
CODE reference to callback to invoke when the timer expires.
The delay in seconds after starting the timer until it expires. Cannot be changed if the timer is running.
Once constructed, the Timer will need to be added to the Loop before it
will work. It will also need to be started by the start method.
Returns true if the Timer has been started, and has not yet expired, or been stopped.
Starts the Timer. Throws an error if it was already running.
If the Timer is not yet in a Loop, the actual start will be deferred until it is added. Once added, it will be running, and will expire at the given duration after the time it was added.
Stops the Timer if it is running.
If the timer is running, restart the countdown period from now. If the timer is not running, this method has no effect.
Paul Evans <leonerd@leonerd.org.uk>
| IO::Async::Timer - event callback after some timed delay |