The timeout in AsyncTimeout is implemented using alarm() which is not automatically delivered on windows. If you can call sleep()
from time to time (in your worker callback) the alarm will get caught.
use strict;
use warnings;
use Async;
my $proc = AsyncTimeout->new(sub{for (1..10000){
print "count: $_\n";
sleep(0);
}
},
1,
"my timeout\n");
while (defined $proc) {
print "Main program: The time is now ", scalar(localtime), "\n";
my $e;
if ($proc->ready) {
if ($e = $proc->error) {
print "Something went wrong. The error was: $e\n";
} else {
print "The result of the computation is: ", $proc->result, "\n";
}
undef $proc;
}
# The result is not ready; we can go off and do something else here.
sleep 1; # One thing we could do is to take nap.
}
print "main process continues\n";
prints
count: ...
count: 5555
The result of the computation is: my timeout
main program continues
This works with strawberry 5.22 and 5.32. If you have to do long running system calls this approach will be of no use.