Skip to content

Commit

Permalink
Go all in on Promises.
Browse files Browse the repository at this point in the history
"Don't worry about it" - let the scheduler handle overscheduling.

Also thread the non-proc version.
  • Loading branch information
coke committed Jun 20, 2018
1 parent 89bf0ab commit 32b51f7
Showing 1 changed file with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions xt/duplicates.t
Expand Up @@ -26,11 +26,6 @@ plan +@files;
my $max-jobs = %*ENV<TEST_THREADS> // 2;
my %output;

sub test-promise($promise) {
my $file = $promise.command[*-1];
test-it(%output{$file}, $file);
}

sub test-it(Str $output, Str $file) {
my $ok = True;

Expand Down Expand Up @@ -76,15 +71,18 @@ for @files -> $file {
my $a = Proc::Async.new($*EXECUTABLE-NAME, '--doc', $file);
%output{$file} = '';
$a.stdout.tap(-> $buf { %output{$file} = %output{$file} ~ $buf });
push @jobs: $a.start;
if +@jobs > $max-jobs {
test-promise(await @jobs.shift)
}
push @jobs: Promise.anyof(
$a.start.then({ test-it(%output{$file}, $file) }),
Promise.in(60)
);
} else {
test-it($file.IO.slurp, $file);
push @jobs: Promise.anyof(
start { test-it($file.IO.slurp, $file) },
Promise.in(60)
);
}
}

for @jobs.map: {await $_} -> $r { test-promise($r) }
await Promise.allof(@jobs);

# vim: expandtab shiftwidth=4 ft=perl6

0 comments on commit 32b51f7

Please sign in to comment.