@@ -21,6 +21,7 @@ has subreaper => 0;
2121has collect_status => 1;
2222has orphans => sub { {} };
2323has process_table => sub { {} };
24+ has collected_info => sub { [] };
2425has ' handler' ;
2526
2627my $singleton ;
@@ -52,7 +53,7 @@ sub enable {
5253 $singleton -> emit(' SIG_CHLD' );
5354 return unless $singleton -> collect_status;
5455 while ((my $pid = waitpid (-1, WNOHANG)) > 0) {
55- $singleton -> collect ($pid => $? => $! );
56+ $singleton -> add_collected_info ($pid , $? , $! );
5657 }
5758 }
5859 });
@@ -66,7 +67,7 @@ sub _collect {
6667}
6768
6869sub collect {
69- my ($errno , $status , $pid ) = ( pop , pop , pop ) ;
70+ my ($self , $pid , $ status , $errno ) = @_ ;
7071 if ($singleton -> resolve($pid )) {
7172 $singleton -> _collect($pid => $status => $errno );
7273 $singleton -> emit(collected => $singleton -> resolve($pid ));
@@ -80,6 +81,17 @@ sub collect {
8081 return $singleton ;
8182}
8283
84+ sub consume_collected_info {
85+ while (my $i = shift @{$singleton -> collected_info}) {
86+ $singleton -> collect(@$i )
87+ }
88+ }
89+
90+ sub add_collected_info {
91+ shift ;
92+ push @{$singleton -> collected_info}, [@_ ];
93+ }
94+
8395# Use as $pid => Mojo::IOLoop::ReadWriteProcess
8496sub register {
8597 my ($process , $pid ) = (pop , pop );
@@ -121,7 +133,7 @@ sub contains {
121133 $singleton -> all-> grep (sub { $_ -> pid eq $pid })-> size == 1;
122134}
123135
124- sub reset { @{+shift }{qw( events orphans process_table) } = ({}, {}, {}) }
136+ sub reset { @{+shift }{qw( events orphans process_table collected_info handler ) } = ({}, {}, {}, [], undef ) }
125137
126138# XXX: This should be replaced by PR_GET_CHILD_SUBREAPER
127139sub disable_subreaper {
0 commit comments