-
-
Save ugexe/a3c1efc1c3c6d4f42fdc to your computer and use it in GitHub Desktop.
RT125758
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Linux | |
> perl6 rt125758.pl6 | |
# STARTED | |
2 | |
1 | |
3 | |
# FINISHED |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# OSX | |
> perl6 rt125758.pl6 | |
# STARTED | |
2 | |
# FINISHED |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Processor { | |
has @.processes; # [[cmd1, cmd2], [cmd3]] | |
has $.process-a1; | |
has $.process-a2; | |
has $.process-b1; | |
submethod BUILD { | |
my $id = 0; | |
$!process-a1 := Proc::Async.new('echo', ++$id); | |
$!process-a2 := Proc::Async.new('echo', ++$id); | |
$!process-b1 := Proc::Async.new('echo', ++$id); | |
@!processes.push([$!process-a1, $!process-a2]); | |
@!processes.push([$!process-b1]); | |
} | |
method start-processes { | |
my $p = Promise.new; | |
$p.keep(1); | |
for @!processes -> $group { | |
$p = $p.then: { | |
my @promises := $group>>.start; | |
await Promise.allof(@promises) if @promises; | |
sleep 5; | |
} | |
} | |
$p; | |
} | |
} | |
my $processor = Processor.new; | |
say "# STARTED"; | |
await $processor.start-processes; | |
say "# FINISHED"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment