On Mon, 2009-07-13 at 23:49 -0400, Chas. Owens wrote:
> #!/usr/bin/perl
> 
> use strict;
> use warnings;
> 
> sub timeout {
>         my ($wait, $code, $timedout, $error) = (@_,
>                 sub { warn $@ }, sub { die $@ });

# I'm just too paranoid to let this pass
        my ( $wait, $code ) = @_;
        my ( $timeout, $error ) = ( sub { warn $@ }, sub { die $@ } );

> 
>         eval {
>                 local $SIG{ALRM} = sub { die "timeout\n" };
>                 alarm $wait;
>                 $code->();
>                 alarm 0;
>                 1;
>         } or do {
>                 alarm 0; #ensure that alarm is not still set
>                 #raise error if it isn't a timeout
>                 if ($@ eq "timeout\n") {
>                         $timedout->();
>                 } else {
>                         $error->();
>                 }
>         };
> }
> 
-- 
Just my 0.00000002 million dollars worth,
  Shawn

Programming is as much about organization and communication
as it is about coding.

Regardless of how small the crowd is, there is always one in
it who has to find out the hard way that the law of gravity
applies to them too.



-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to