Trying to wrap my head around event programming, I ran into this error. My script:
#perl use AnyEvent; my $input_waiting = AnyEvent->condvar; my $output_waiting = AnyEvent->condvar; my $input_from_stdin = AnyEvent->io ( fh => \*STDIN, # which file handle to check poll => "r", # which event to wait for ("r"ead data) cb => sub { # what callback to execute my $input = <STDIN>; # read it push(@input, $input); $input_waiting->send; $output_waiting->recv; print shift(@output) ."\n"; } ); while(1){ # this "blocks" (while handling events) till the callback # calls ->send $input_waiting->recv; ## do some possibly lengthy processing push(@output, 'done'); $output_waiting->send; ## finish this cycle, ## AnyEvent docs say: "You can only wait once on a condition - add +itional calls are valid but will return immediately." ## but we need to stop this loop again, so this: $input_waiting = AnyEvent->condvar; }
As you can see, I am trying to implement a simple Input->process->Output mechanism, like for example chatbots use it. Where the printing of the output should be delayed as long as the processing takes. Is my overall design design okay for that?

Second, as I understand the condvar/signalling logic in AnyEvent, I can use a ->rcv once to halt my processing loop, but after that I can't tell it to go back to sleep as "You can only wait once on a condition". So I need to redeclare a new condvar - is that right?

Third, I need to halt my processing until some input arrives in @input. By doing a ->send in my input waiter I trigger the processing to take place. But how do I halt the input waiter until @output contains some value?
I can't return the @output from some other point in my code as what it is done here via STDIN/STDOUT may as well be a http connected client where I can't simply append data. I need to halt the code in $input_from_stdin for as long as the processing needs so I keep this "sessing" alive there.

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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.