diff options
author | Eric Wong <e@80x24.org> | 2017-01-11 04:12:26 +0000 |
---|---|---|
committer | Eric Wong <e@80x24.org> | 2019-01-22 03:38:39 +0000 |
commit | b490ce09b370d9398d5332ca1dc6260a7ec0aa6c (patch) | |
tree | 4cd4620d559aecaec8ff425e9d7ac3fe5da55a23 /lib/PublicInbox/GetlineBody.pm | |
parent | da9beb99af585718c36725f3457b1b72347bcebf (diff) | |
download | public-inbox-b490ce09b370d9398d5332ca1dc6260a7ec0aa6c.tar.gz |
This is intended for wrapping "git show" and "git diff" processes in the future and to prevent it from monopolizing callers. This will us to better handle backpressure from gigantic commits.
Diffstat (limited to 'lib/PublicInbox/GetlineBody.pm')
-rw-r--r-- | lib/PublicInbox/GetlineBody.pm | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/lib/PublicInbox/GetlineBody.pm b/lib/PublicInbox/GetlineBody.pm index ea07f3d6..0a922fd2 100644 --- a/lib/PublicInbox/GetlineBody.pm +++ b/lib/PublicInbox/GetlineBody.pm @@ -13,8 +13,13 @@ use strict; use warnings; sub new { - my ($class, $rpipe, $end, $buf) = @_; - bless { rpipe => $rpipe, end => $end, buf => $buf }, $class; + my ($class, $rpipe, $end, $buf, $filter) = @_; + bless { + rpipe => $rpipe, + end => $end, + buf => $buf, + filter => $filter || 0, + }, $class; } # close should always be called after getline returns undef, @@ -24,8 +29,13 @@ sub DESTROY { $_[0]->close } sub getline { my ($self) = @_; + my $filter = $self->{filter}; + return if $filter == -1; # last call was EOF + my $buf = delete $self->{buf}; # initial buffer - defined $buf ? $buf : $self->{rpipe}->getline; + $buf = $self->{rpipe}->getline unless defined $buf; + $self->{filter} = -1 unless defined $buf; # set EOF for next call + $filter ? $filter->($buf) : $buf; } sub close { |