Async
view release on metacpan or search on metacpan
106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147sub
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 {
my
(
$class
,
$task
) = (
shift
,
@_
);
my
$newtask
=
sub
{
my
$v
=
$task
->();
return
Storable::freeze(
$v
);
};
$class
->SUPER::new(
$newtask
);
}
sub
result {
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 0.344 second using v1.01-cache-2.11-cpan-8d75d55dd25 )