Skip to content

Commit

Permalink
fixed another timeout bug in Mojo::IOLoop::Stream
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Aug 8, 2013
1 parent 7f66812 commit 786af75
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
12 changes: 6 additions & 6 deletions lib/Mojo/IOLoop/Stream.pm
Expand Up @@ -46,14 +46,14 @@ sub is_writing {
sub start {
my $self = shift;

my $reactor = $self->reactor;
my $cb = sub { pop() ? $self->_write : $self->_read };
$reactor->io($self->timeout($self->{timeout})->{handle} => $cb)
unless $self->{timer};

# Resume
$reactor->watch($self->{handle}, 1, $self->is_writing)
my $reactor = $self->reactor;
return $reactor->watch($self->{handle}, 1, $self->is_writing)
if delete $self->{paused};

weaken $self;
my $cb = sub { pop() ? $self->_write : $self->_read };
$reactor->io($self->timeout($self->{timeout})->{handle} => $cb);
}

sub stop {
Expand Down
2 changes: 2 additions & 0 deletions t/mojo/ioloop.t
Expand Up @@ -131,11 +131,13 @@ Mojo::IOLoop->client(
$handle = $delay->wait->steal_handle;
my $stream = Mojo::IOLoop::Stream->new($handle);
is $stream->timeout, 15, 'right default';
is $stream->timeout(16)->timeout, 16, 'right timeout';
$id = Mojo::IOLoop->stream($stream);
$stream->on(close => sub { Mojo::IOLoop->stop });
$stream->on(read => sub { $buffer .= pop });
$stream->write('hello');
ok(Mojo::IOLoop->stream($id), 'stream exists');
is $stream->timeout, 16, 'right timeout';
Mojo::IOLoop->start;
Mojo::IOLoop->timer(0.25 => sub { Mojo::IOLoop->stop });
Mojo::IOLoop->start;
Expand Down

0 comments on commit 786af75

Please sign in to comment.