Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: AnyEvent - sequence of async operations without recursion?

by kschwab (Vicar)
on Feb 10, 2021 at 22:38 UTC ( #11128201=note: print w/replies, xml ) Need Help??


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 (Scribe) 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!

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11128201]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (2)
As of 2021-09-17 05:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?