0x1949 Team - FAZEMRX - MANAGER
Edit File: Time::Out.3pm
.\" Automatically generated by Pod::Man 4.14 (Pod::Simple 3.42) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" ======================================================================== .\" .IX Title "Time::Out 3pm" .TH Time::Out 3pm "2023-11-27" "perl v5.34.0" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" Time::Out \- Easily timeout long running operations .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 1 \& 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 \& } .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" The \f(CW\*(C`Time::Out\*(C'\fR module provides an easy interface to \fBalarm\fR\|(2) based timeouts. Nested timeouts are supported. The module exports the \f(CW\*(C`timeout()\*(C'\fR function by default. The function returns whatever the code placed inside the subroutine reference returns: .PP .Vb 1 \& use Time::Out qw( timeout ); \& \& my $result = timeout 5 => sub { \& return 7; \& }; \& # $result == 7 .Ve .PP If \f(CW\*(C`Time::Out\*(C'\fR sees that Time::HiRes has been loaded, it will use that \&\f(CW\*(C`alarm()\*(C'\fR function (if available) instead of the default one, allowing float timeout values to be used effectively: .PP .Vb 2 \& use Time::HiRes qw(); \& use Time::Out qw( timeout ); \& \& timeout 3.1416 => sub { \& # ... \& }; .Ve .SH "CAVEATS" .IX Header "CAVEATS" .IP "Blocking I/O on MSWin32" 2 .IX Item "Blocking I/O on MSWin32" \&\fBalarm\fR\|(2) doesn't interrupt blocking I/O on MSWin32, so \f(CW\*(C`timeout()\*(C'\fR won't do that either. .ie n .IP "@_" 2 .el .IP "\f(CW@_\fR" 2 .IX Item "@_" One drawback to using \f(CW\*(C`timeout()\*(C'\fR is that it masks \f(CW@_\fR in the affected code. This happens because the affected code is actually wrapped inside another subroutine that provides it's own \f(CW@_\fR. You can get around this by specifically passing your \f(CW@_\fR (or whatever you want for that matter) to \&\f(CW\*(C`timeout()\*(C'\fR as such: .Sp .Vb 1 \& use Time::Out qw( timeout ); \& \& sub foo { \& timeout 5, @_ => sub { \& @_; \& }; \& } \& my @result = foo( 42, "Hello, World!" ); \& # @result == ( 42, "Hello, World!" ); .Ve .IP "Eval inside timeout" 2 .IX Item "Eval inside timeout" If the affected code has its own exception handling using Try::Tiny for example, the catch block has to be amended in a way so that it will rethrow an exception, if it refers to a timeout: .Sp .Vb 3 \& use Scalar::Util qw( blessed ); \& use Time::Out qw( timeout ); \& use Try::Tiny qw( catch try ); \& \& timeout 5, sub { \& try { \& select( undef, undef, undef, 7 ); \& die "bad\en"; \& } catch { \& # rethrow exception, if it refers to a timeout \& die $_ if blessed $_ && $_\->isa( \*(AqTime::Out::Exception\*(Aq ); \& # handle all other exceptions \& } \& }; .Ve .SH "SEE ALSO" .IX Header "SEE ALSO" \&\fBalarm\fR\|(2), Sys::AlarmCall .SH "AUTHORS" .IX Header "AUTHORS" Sven Willenbuecher, <sven.willenbuecher@gmx.de> .PP Patrick LeBoutillier, <patl@cpan.org> .SH "COPYRIGHT AND LICENSE" .IX Header "COPYRIGHT AND LICENSE" This software is copyright (c) 2005\-2008 Patrick LeBoutillier, 2023 by Sven Willenbuecher. .PP This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.