Skip to content

Instantly share code, notes, and snippets.

@peczenyj
Forked from marcioferreira/gist:7431697
Created November 12, 2013 14:36
Show Gist options
  • Save peczenyj/7431827 to your computer and use it in GitHub Desktop.
Save peczenyj/7431827 to your computer and use it in GitHub Desktop.
use Time::Out qw(timeout);
use DDP;
sub run_with_timeout(&$$) {
my $block = shift;
my $timeout = shift;
timeout $timeout, @_ => sub {
my $pool = shift;
while ( my $s = pop @$pool ) {
$block->($s);
}
};
return @_;
}
my ($t) = run_with_timeout { print "$_[0]\n"; sleep $_[0]; } 10, [ 42, 3, 5, 1, 4, 2 ] ;
p $t
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment