Thanks that was exactly what I was after! Works great:
use strict;
use warnings;
use AnyEvent;
use AnyEvent::FIFO;
my $cv = AnyEvent::condvar;
my $fifo = AnyEvent::FIFO->new(
max_active => 1, # max "concurrent" callbacks to execute per slot
);
my @q1 = (9,8,7,6,5,4,3,2,1);
my @q2 = qw(a b c d e f g h i);
foreach my $item (@q1) { $fifo->push( "number_queue", \&callback1, $it
+em); }
foreach my $item (@q2) { $fifo->push( "letter_queue", \&callback2, $it
+em); }
#do other async stuff here...
$cv->recv;
my ($q1t,$q2t);
sub callback1
{
my ($guard,$item) = @_;
$q1t = AnyEvent->timer(after=>1, interval => 0, cb => sub {
print "Got $item\n";
undef $guard;
});
}
sub callback2
{
my ($guard,$item) = @_;
$q2t = AnyEvent->timer(after=>1, interval => 0, cb => sub {
print "Got $item\n";
undef $guard;
});
}
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.