Skip to content

Instantly share code, notes, and snippets.

@autarch
Created December 6, 2015 19:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save autarch/cfa68f65b36a8cd5cd0b to your computer and use it in GitHub Desktop.
Save autarch/cfa68f65b36a8cd5cd0b to your computer and use it in GitHub Desktop.
method !run-with-progress ($items, Routine $sub, Str $msg = q{ done}) {
my $prog = Term::ProgressBar.new( :count( $items.elems ), :p )
if $!verbose;
my $supply = $items.Supply;
if $!threads > 1 {
my $sched = ThreadPoolScheduler.new( :max_threads($!threads) );
$supply = $supply.schedule-on($sched);
}
my $i = 1;
$supply.tap(
sub ($item) {
$sub($item);
say "THREAD #{$*THREAD.id}";
$prog.?update($i);
$i++;
}
);
$supply.wait;
$prog.?message($msg);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment