Skip to content

Commit

Permalink
make sure the second callback does not get executed before the event …
Browse files Browse the repository at this point in the history
…loop has been started
  • Loading branch information
kraih committed Aug 28, 2016
1 parent 8bfafaa commit 637ff48
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
4 changes: 2 additions & 2 deletions lib/Mojo/IOLoop/Subprocess.pm
Expand Up @@ -42,8 +42,8 @@ sub run {
close => sub {
waitpid $self->{pid}, 0;
return $self->$parent("Non-zero exit status (@{[$? >> 8]})") if $?;
my $result = eval { $self->deserialize->($buffer) } || [];
$self->$parent(shift(@$result) // $@, @$result);
my $results = eval { $self->deserialize->($buffer) } || [];
$self->$parent(shift(@$results) // $@, @$results);
}
);
return $self;
Expand Down
7 changes: 4 additions & 3 deletions t/mojo/subprocess.t
Expand Up @@ -17,13 +17,14 @@ $subprocess->run(
sub { shift->pid . $$ . ('x' x 100000) },
sub {
my ($subprocess, $err, $two) = @_;
$fail = $err;
$result = $two;
$fail = $err;
$result .= $two;
}
);
$result = $$;
Mojo::IOLoop->start;
ok !$fail, 'no error';
is $result, 0 . $subprocess->pid . ('x' x 100000), 'right result';
is $result, $$ . 0 . $subprocess->pid . ('x' x 100000), 'right result';

# Custom event loop
($fail, $result) = ();
Expand Down

0 comments on commit 637ff48

Please sign in to comment.