Anything wrong with using AnyEvent::Handle for files?

Mike Schilli office at perlmeister.com
Fri Aug 7 17:19:13 CEST 2015


Although the documentation seems to discourage using AnyEvent::Handle
for anything but streaming things like sockets and pipes, using it for
files seems to work fine in the code below.
Any reason not to use it in this way?

use AnyEvent;
use AnyEvent::Handle;

open my $fh, "<", "foo.txt" or die;

my $handle = AnyEvent::Handle->new(
    fh       => $fh,
    on_error => sub { die "read error: $!"; },
    on_eof   => sub { print "done!\n"; },
    on_read  => sub {
        my( $hdl ) = @_;

        $hdl->push_read( line => sub {
            my( $h, $line ) = @_;
            print "line=$line\n";
        } );
    },
);

AnyEvent->condvar->recv;



More information about the anyevent mailing list