Piping with AnyEvent::Handle

yon ar c'hall yon.ar.chall at gmail.com
Wed Mar 16 09:56:22 CET 2011


Thanks for the explanations, Marc.

What you would have to do is keep your handle object around and destroy it
> when finished, for example, when you want to just read that line, do this:
>
>    my $aer; $aer = new AnyEvent::Handle fh => $r;
>    $aer->push_read(line => sub {
>        my (undef, $line) = @_;
>        print "<$line>\n";
>         undef $aer; # keep $aer from being destructed until here
>    });
>

Making an "undef $aer" inside the callback is not natural for me. I have to
make the effort to think differently (especially taking care about variable
scope) when doing event programming. Some remarks : instead of "undef
$aer;", we could have just write "$aer;" (if we want to read more than one
line). If I understand well, it's just a way of keeping a reference to the
variable "$aer", so that Perl does not automatically destroy it. Also, the
"my $aer;" instruction is not mandatory in the present case, isn't it ? (we
could have simply code "my $aer = new ...").


> So in general, once you created your handle object, it should become *the
> handle*, i.e. you should not keep the original fh around.
>

Here, I don't see how to implement this. Could you please explain further
(based on the present pipe example) ?

Yon
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.schmorp.de/pipermail/anyevent/attachments/20110316/fae8fbb4/attachment.html>


More information about the anyevent mailing list