Skip site navigation (1)Skip section navigation (2)

FreeBSD Manual Pages

  
 
  

home | help
Out(3)		      User Contributed Perl Documentation		Out(3)

NAME
       Time::Out - Easily timeout long running operations

SYNOPSIS
	 use Time::Out qw(timeout) ;

	 timeout $nb_secs => sub {
	   # your code goes were and will be interrupted if it runs
	   # for more than $nb_secs seconds.
	 } ;
	 if ($@){
	   # operation timed-out
	 }

DESCRIPTION
       "Time::Out" provides an easy interface to alarm(2) based	timeouts.
       Nested timeouts are supported.

   RETURN VALUE
       'timeout' returns whatever the code placed inside the block returns:

	 use Time::Out qw(timeout) ;

	 my $rc	= timeout 5 => sub {
	       return 7	;
	 } ;
	 # $rc == 7

"Time::HiRes"
       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::Out ;
	 use Time::HiRes ;

	 timeout 3.1416	=> sub {
	       # ...
	 } ;

BUGS
       Blocking	I/O on MSWin32
	   alarm(2) doesn't interrupt blocking I/O on MSWin32, so 'timeout'
	   won't do that either.

       @_  One drawback	to using 'timeout' is that it masks @_ in the affected
	   code.  This happens because the affected code is actually wrapped
	   inside another subroutine that provides it's	own @_.	You can	get
	   around this by specifically passing your @_ (or whatever you	want
	   for that matter) to 'timeout' as such:

	     use Time::Out ;

	     sub test {
	       timeout 5, @_ =>	sub {
		 print "$_[0]\n" ;
	       } ;
	     }

	     test("hello") ; # will print "hello\n" ;

SEE ALSO
       eval, closures, alarm(2), Sys::AlarmCall

AUTHOR
       Patrick LeBoutillier, <patl@cpan.org>

COPYRIGHT AND LICENSE
       Copyright 2005-2008 by Patrick LeBoutillier

       This library is free software; you can redistribute it and/or modify it
       under the same terms as Perl itself.

perl v5.32.1			  2009-05-04				Out(3)

NAME | SYNOPSIS | DESCRIPTION | "Time::HiRes" | BUGS | SEE ALSO | AUTHOR | COPYRIGHT AND LICENSE

Want to link to this manual page? Use this URL:
<https://www.freebsd.org/cgi/man.cgi?query=Time::Out&sektion=3&manpath=FreeBSD+13.0-RELEASE+and+Ports>

home | help