Subject: | ->read_until / ->read_exactly / ->read_* Future is already done |
Attached script raises an exception due to future being marked ->done after completion. More details to follow...
cheers,
Tom
Subject: | read_until.t |
use strict;
use warnings;
use Test::More;
use Test::Fatal;
use IO::Async::Loop;
use IO::Async::Stream;
my $loop = IO::Async::Loop->new;
my $listener = $loop->listen(
addr => {
family => 'inet',
socktype => 'stream',
ip => '127.0.0.1',
port => 0,
},
on_stream => sub {
my ($stream) = @_;
$stream->configure(
on_read => sub {
my ($stream, $buf, $eof) = @_;
$stream->debug_printf("Had line: %s", $1) while $$buf =~ s/^(.+)\x0D\x0A//;
0
}
);
$loop->add($stream);
$stream->write('lalalalalalalalala');
}
)->get;
my $port = $listener->read_handle->sockport;
$loop->connect(
addr => {
family => 'inet',
socktype => 'stream',
ip => '127.0.0.1',
port => $port,
},
)->then(sub {
my ($sock) = @_;
my $stream = IO::Async::Stream->new(
handle => $sock,
on_read => sub { 0 }
);
$loop->add($stream);
Future->done($stream);
})->then(sub {
my ($stream) = @_;
$stream->read_exactly(4)->then(sub {
$stream->read_exactly(4)
})
})->get