http://qs321.pair.com?node_id=11128201


in reply to AnyEvent - sequence of async operations without recursion?

AnyEvent::FIFO maybe?

The source code is pretty short, seems like AnyEvent::Util::guard is what's used to implement the FIFO

  • Comment on Re: AnyEvent - sequence of async operations without recursion?

Replies are listed 'Best First'.
Re^2: AnyEvent - sequence of async operations without recursion?
by sectokia (Pilgrim) on Feb 11, 2021 at 01:49 UTC

    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; }); }
      Glad it worked out for you!