Skip to content

Instantly share code, notes, and snippets.

@melo
Created October 20, 2013 07:47
Show Gist options
  • Save melo/7066163 to your computer and use it in GitHub Desktop.
Save melo/7066163 to your computer and use it in GitHub Desktop.
Coro::Channel will round-robin between threads, nice...
#!/usr/bin/env perl
use common::sense;
use Coro;
my $req = Coro::Channel->new;
my $rep = Coro::Channel->new;
sub start_worker {
my $name = shift;
async {
while (1) {
my $something = $req->get;
$rep->put("$name: $something");
}
};
}
start_worker('first');
start_worker('second');
for (1 .. 100) {
$req->put($_);
say $rep->get;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment