Here is the code
printsuse strict; sub Call_with_Timeout{ my ($TIMEOUT, $CODEREF) = @_; eval { local $SIG{ALRM} = sub { die "alarm time out" }; alarm $TIMEOUT; $CODEREF->(); # Whatever needs to be done alarm 0; 1; # return value from eval on normalcy } or return -1; # Timeout happened return 1; # OK } my $t=Call_with_Timeout(3, sub{ sleep 3, print "$_.\n" for 1..2}); print "Timed out=$t;\n";
"As you get older three things happen. The first is your memory goes, and I can't remember the other two... " - Sir Norman Wisdom
In reply to Re: Waiting for Alarm
by NetWallah
in thread Waiting for Alarm
by n8ur
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |