Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
with modules like EV the exit status is just not reliable enough
  • Loading branch information
kraih committed Aug 29, 2016
1 parent c9816ac commit 2055ae7
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
8 changes: 3 additions & 5 deletions lib/Mojo/IOLoop/Subprocess.pm
Expand Up @@ -36,14 +36,12 @@ sub run {
# Parent
my $stream = Mojo::IOLoop::Stream->new($reader);
$self->ioloop->stream($stream);
my $buffer;
my $buffer = '';
$stream->on(read => sub { $buffer .= pop });
$stream->on(
close => sub {
my $results
= waitpid($pid, 0) == $pid && $?
? ["Non-zero exit status (@{[$? >> 8]})"]
: eval { $self->deserialize->($buffer) } || [];
waitpid $pid, 0;
my $results = eval { $self->deserialize->($buffer) } || [];
$self->$parent(shift(@$results) // $@, @$results);
}
);
Expand Down
4 changes: 2 additions & 2 deletions t/mojo/subprocess.t
Expand Up @@ -96,7 +96,7 @@ is_deeply $result, [1, 2], 'right structure';
# No result
($fail, $result) = ();
Mojo::IOLoop::Subprocess->new->run(
sub { exit 0 },
sub {return},
sub {
my ($subprocess, $err, @results) = @_;
$fail = $err;
Expand Down Expand Up @@ -129,7 +129,7 @@ Mojo::IOLoop::Subprocess->new->run(
}
);
Mojo::IOLoop->start;
is $fail, 'Non-zero exit status (3)', 'right error';
like $fail, qr/Storable/, 'right error';

# Serialization error
$fail = undef;
Expand Down

0 comments on commit 2055ae7

Please sign in to comment.