We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 5c404d2 commit 9981531Copy full SHA for 9981531
demo.pl
@@ -81,3 +81,18 @@ ($)
81
}
82
sub realpath($) { return to_utf8(Cwd::realpath(@_)); }
83
sub bsd_glob($) { return map {to_utf8($_)} File::Glob::bsd_glob(@_); }
84
+
85
+# perform a code block and prevent it from blocking by using a timeout
86
+sub do_timeout($&)
87
+{
88
+ my ($seconds, $code) = @_;
89
+ local $SIG{ALRM} = sub {die "alarm clock restart executing $code"};
90
+ alarm $seconds; # schedule an alarm in a few seconds
91
+ eval {
92
+ &$code; # execute the code block or subroutine passed in
93
+ alarm 0; # cancel the alarm
94
+ };
95
+ if ($@ and $@ !~ /^alarm clock restart/) {die $@};
96
+} # noblock()
97
98
+do_timeout 10, sub { print "Hello, World!\n"};
0 commit comments