|
NAMETime::Out - Easily timeout long running operations SYNOPSIS use Time::Out qw( timeout );
timeout $timeout => sub {
# your operation is implemented here and will be interrupted
# if it runs for more than $timeout seconds
};
if ( $@ ) {
# operation timed-out
}
DESCRIPTIONThe "Time::Out" module provides an easy interface to alarm(2) based timeouts. Nested timeouts are supported. The module exports the timeout() function by default. The function returns whatever the code placed inside the subroutine reference returns: use Time::Out qw( timeout );
my $result = timeout 5 => sub {
return 7;
};
# $result == 7
If "Time::Out" sees that Time::HiRes has been loaded, it will use that alarm() function (if available) instead of the default one, allowing float timeout values to be used effectively: use Time::HiRes qw();
use Time::Out qw( timeout );
timeout 3.1416 => sub {
# ...
};
CAVEATS
SEE ALSOalarm(2), Sys::AlarmCall AUTHORSSven Willenbuecher, <sven.willenbuecher@gmx.de> Patrick LeBoutillier, <patl@cpan.org> COPYRIGHT AND LICENSEThis software is copyright (c) 2005-2008 Patrick LeBoutillier, 2023 by Sven Willenbuecher. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
|