Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added progress notifications to Mojo::IOLoop::Subprocess #1286

Merged
merged 1 commit into from
Nov 8, 2018
Merged

added progress notifications to Mojo::IOLoop::Subprocess #1286

merged 1 commit into from
Nov 8, 2018

Conversation

akarelas
Copy link
Contributor

@akarelas akarelas commented Nov 6, 2018

Summary

Added 'progress' method and event to Mojo::IOLoop::Subprocess, in accordance to kraih's specifications. Includes test, but no documentation just yet.

Motivation

This pull-request comes after an issue for its implementation was written in the mojo project

References

issue #1285

@@ -10,6 +10,7 @@ use Storable;
has deserialize => sub { \&Storable::thaw };
has ioloop => sub { Mojo::IOLoop->singleton }, weak => 1;
has serialize => sub { \&Storable::freeze };
has _progress_writer => undef, weak => 1;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't use private attribute accessors. Why do you need to weaken the reference?

Copy link
Contributor Author

@akarelas akarelas Nov 6, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I weakened the reference thinking that would allow the pipe to disappear once ->run completes (but before $subprocess goes out of scope), and thus save on resources. Is there something wrong with that thinking?

$snippet =~ s/\A$length\-//;
my $args = $self->deserialize->($snippet);
$self->emit(progress => @$args);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This block is in need of some golfing, it seems way too verbose. 😉

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pos can replace the length($length) + 1

        my ($length, $s) = (($progress_buffer =~ m/\A(\d+)\-/gc), pos($progress_buffer));
        defined $length or last;
        length($prog_buffer) >= ($length += $s) or last;
        my $args = $self->deserialize->(substr substr($progress_buffer, 0, $length, ''), $s);
        $self->emit(progress => @$args);

@kraih
Copy link
Member

kraih commented Nov 7, 2018

Squash your commits.

# Child
return $self->$parent("Can't fork: $!")
unless defined(my $pid = $self->{pid} = fork);
unless ($pid) {
close $progress_reader;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why does $progress_reader need to be closed manually, but not $reader?

@marcusramberg
Copy link
Member

lgtm 👌

@kraih kraih merged commit 47fa774 into mojolicious:master Nov 8, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants