summaryrefslogtreecommitdiff
path: root/lib/IO/Async/Timer
diff options
context:
space:
mode:
authorJonathan Yu <jawnsy@cpan.org>2009-11-24 03:14:37 +0000
committerJonathan Yu <jawnsy@cpan.org>2009-11-24 03:14:37 +0000
commit81a947857837079f112ddac1a5a403c80b6b4d19 (patch)
tree2d71ccf6237fc8955ba9ce29c8c513678a0b56c1 /lib/IO/Async/Timer
parenta3705f4e412f5a8aea40f1c0da9e36c2fbf7c7a1 (diff)
[svn-upgrade] Integrating new upstream version, libio-async-perl (0.26)
Diffstat (limited to 'lib/IO/Async/Timer')
-rw-r--r--lib/IO/Async/Timer/Countdown.pm48
-rw-r--r--lib/IO/Async/Timer/Periodic.pm2
2 files changed, 48 insertions, 2 deletions
diff --git a/lib/IO/Async/Timer/Countdown.pm b/lib/IO/Async/Timer/Countdown.pm
index 35ed5e8..a3abf0b 100644
--- a/lib/IO/Async/Timer/Countdown.pm
+++ b/lib/IO/Async/Timer/Countdown.pm
@@ -9,7 +9,7 @@ use strict;
use warnings;
use base qw( IO::Async::Timer );
-our $VERSION = '0.25';
+our $VERSION = '0.26';
use Carp;
use Scalar::Util qw( weaken );
@@ -178,6 +178,52 @@ sub reset
__END__
+=head1 EXAMPLES
+
+=head2 Watchdog Timer
+
+Because the C<reset> method restarts a running countdown timer back to its
+full period, it can be used to implement a watchdog timer. This is a timer
+which will not expire provided the method is called at least as often as it
+is configured. If the method fails to be called, the timer will eventually
+expire and run its callback.
+
+For example, to expire an accepted connection after 30 seconds of inactivity:
+
+ ...
+
+ on_accept => sub {
+ my ( $newclient ) = @_;
+
+ my $stream;
+
+ my $watchdog = IO::Async::Timer::Countdown->new(
+ delay => 30,
+
+ on_expire => sub { $stream->close },
+ );
+
+ my $stream = IO::Async::Stream->new(
+ handle => $newclient,
+
+ on_read => sub {
+ my ( $self, $buffref, $closed ) = @_;
+ $stream->reset;
+
+ ...
+ },
+
+ on_closed => sub {
+ $watchdog->stop;
+ },
+ ) );
+
+ $watchdog->start;
+
+ $loop->add( $stream );
+ $loop->add( $watchdog );
+ }
+
=head1 AUTHOR
Paul Evans <leonerd@leonerd.org.uk>
diff --git a/lib/IO/Async/Timer/Periodic.pm b/lib/IO/Async/Timer/Periodic.pm
index 79edc60..7900532 100644
--- a/lib/IO/Async/Timer/Periodic.pm
+++ b/lib/IO/Async/Timer/Periodic.pm
@@ -9,7 +9,7 @@ use strict;
use warnings;
use base qw( IO::Async::Timer );
-our $VERSION = '0.25';
+our $VERSION = '0.26';
use Carp;
use Scalar::Util qw( weaken );