Created
March 15, 2015 18:57
-
-
Save hoelzro/bd4608729d7be342ccda to your computer and use it in GitHub Desktop.
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
use v6; | |
use HTTP::UserAgent; | |
sub worker(Channel $in, Supply $out) { | |
for @$in -> [ $index, $url ] { | |
$out.emit: "$index $url"; | |
} | |
say 'done'; | |
} | |
my $channel = Channel.new; | |
my $results = Supply.new; | |
my @workers = (^10).map: { | |
start { worker($channel, $results) } | |
}; | |
for ^100 -> $i { | |
$channel.send: [ $i, 'http://localhost:5000/index.html' ]; | |
} | |
$channel.close; | |
await @workers; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
sub worker(Channel $in, Supply $out, $id) {
say "$id started";
loop {
my $work = try $in.receive;
last if !$work.defined;
$out.emit: $work;
say "$id got $work";
}
say "$id done";
}
my $channel = Channel.new;
my $results = Supply.new;
my @Workers = (^10).map: {
start { say "started worker"; worker($channel, $results, $_) }
}
say "start sending";
for ^100 -> $i {
say "sent $i";
$channel.send: [ $i, 'http://localhost:5000/index.html' ];
}
$channel.close;
await @Workers;
say "all workers done";