Async
view release on metacpan or search on metacpan
sub new {
my ( $class, $task, $timeout, $msg ) = ( shift, @_ );
$msg = "Timed out\n" unless defined $msg;
my $newtask = sub {
local $SIG{'ALRM'} = sub { die "TIMEOUT\n" };
alarm $timeout;
my $s = eval { $task->() };
return $msg if not defined $s and $@ eq "TIMEOUT\n";
return $s;
};
$class->SUPER::new( $newtask );
}
package AsyncData;
our $VERSION = '0.14';
our @ISA = 'Async';
sub new {
require Storable;
my ( $class, $task ) = ( shift, @_ );
my $newtask = sub {
my $v = $task->();
return Storable::freeze( $v );
};
$class->SUPER::new( $newtask );
}
sub result {
require Storable;
my $self = shift;
my $rc = $self->SUPER::result( @_ );
return defined $rc ? Storable::thaw( $rc ) : $rc;
}
1;
__END__
=head1 NAME
Async - Asynchronous evaluation of Perl code (with optional timeouts)
( run in 1.534 second using v1.01-cache-2.11-cpan-a9ef4e587e4 )