| IO::Async::Timer::Countdown |
IO::Async::Timer::Countdown - event callback after a fixed delay
use IO::Async::Timer::Countdown;
use IO::Async::Loop; my $loop = IO::Async::Loop->new();
my $timer = IO::Async::Timer::Countdown->new(
delay => 10,
on_expire => sub {
print "Sorry, your time's up\n";
$loop->loop_stop;
},
);
$timer->start;
$loop->add( $timer );
$loop->loop_forever;
This module provides a subclass of the IO::Async::Timer manpage for implementing one-shot fixed delays. The 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.
For a Timer object that repeatedly runs a callback at regular intervals,
see instead the IO::Async::Timer::Periodic manpage.
This object may be used in one of two ways; with a callback function, or as a base class.
If the on_expire key is supplied to the constructor, it should contain a
CODE reference to a callback function to be invoked at the appropriate time:
$on_expire->( $self )
If a subclass is built, then it can override the on_expire method.
$self->on_expire()
The following named parameters may be passed to new or configure:
CODE reference to callback to invoke when the timer expires. If not supplied, the subclass method will be called instead.
The delay in seconds after starting the timer until it expires. Cannot be changed if the timer is running.
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.
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::Countdown |