Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: Doing an Input->process->Output cycle with AnyEvent? (was: error: "recursive blocking wait detected")

by james2vegas (Chaplain)
on Oct 17, 2010 at 00:16 UTC ( [id://865750]=note: print w/replies, xml ) Need Help??


in reply to Doing an Input->process->Output cycle with AnyEvent? (was: error: "recursive blocking wait detected")

Wrap the creation of your condvars and AE::io objects in your while loop and use callbacks on the condvars instead of procedural code to do the sequential tasks, something like this:
#!/usr/bin/perl use strict; use warnings; use AnyEvent; while (1) { my $cv = AE::cv; my (@output, @input); my $input_waiting = AE::cv; my $output_waiting = AE::cv; my $input_from_stdin = AE::io *STDIN, 0, sub { my $input = <STDIN>; # read it push(@input, $input); $input_waiting->send; }; # what to do when $input_waiting has sent $input_waiting->cb( sub { push(@output, 'done'); $output_waiting->send; }); # what to do when $output_waiting has sent $output_waiting->cb( sub { print shift(@output) ."\n"; $cv->send; }); # wait for the main condvar $cv->recv; }
the while block ensures that new condvars and AE::io objects get created on each iteration of the loop. I used the simpler AE API, but that shouldn't affect the functioning of the code. You could probably get by without the $cv condvar, but it may be helpful as this is part of a larger application. You should look at the begin and end methods of AE::condvar which enables the use of single condvars as mergepoints for events, and Object::Event for a lightweight event registration and emitting library.
  • Comment on Re: Doing an Input->process->Output cycle with AnyEvent? (was: error: "recursive blocking wait detected")
  • Select or Download Code

Replies are listed 'Best First'.
Re^2: Doing an Input->process->Output cycle with AnyEvent? (was: error: "recursive blocking wait detected")
by isync (Hermit) on Oct 17, 2010 at 01:21 UTC
    Thanks for your design input. As I mentioned in my previous reply to BrowserUk, I am tempted to walk away from event based programming for the task, at least for now.

    But before I do I will give it a last try with your proposed structure. As I've learned from your post, redeclaring condvars over and over again seems to be okay to send the overall system into stop and start states, as I can use a cv only once.
    I've already looked into the begin/end methods a bit, but so far did not need its "counter" mechanism. We'll see.

    Again, thanks!

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (3)
As of 2024-04-19 05:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found