Acme-Sort-Sleep
view release on metacpan or search on metacpan
local/lib/perl5/IO/Async/PID.pm view on Meta::CPAN
# You may distribute under the terms of either the GNU General Public License
# or the Artistic License (the same terms as Perl itself)
#
# (C) Paul Evans, 2010-2011 -- leonerd@leonerd.org.uk
package IO::Async::PID;
use strict;
use warnings;
use base qw( IO::Async::Notifier );
our $VERSION = '0.70';
use Carp;
=head1 NAME
C<IO::Async::PID> - event callback on exit of a child process
=head1 SYNOPSIS
use IO::Async::PID;
use POSIX qw( WEXITSTATUS );
use IO::Async::Loop;
my $loop = IO::Async::Loop->new;
my $kid = $loop->fork(
code => sub {
print "Child sleeping..\n";
sleep 10;
print "Child exiting\n";
return 20;
},
);
print "Child process $kid started\n";
my $pid = IO::Async::PID->new(
pid => $kid,
on_exit => sub {
my ( $self, $exitcode ) = @_;
printf "Child process %d exited with status %d\n",
$self->pid, WEXITSTATUS($exitcode);
},
);
$loop->add( $pid );
$loop->run;
=head1 DESCRIPTION
This subclass of L<IO::Async::Notifier> invokes its callback when a process
exits.
For most use cases, a L<IO::Async::Process> object provides more control of
setting up the process, connecting filehandles to it, sending data to and
receiving data from it.
=cut
=head1 EVENTS
The following events are invoked, either using subclass methods or CODE
references in parameters:
=head2 on_exit $exitcode
Invoked when the watched process exits.
=cut
=head1 PARAMETERS
The following named parameters may be passed to C<new> or C<configure>:
=head2 pid => INT
The process ID to watch. Must be given before the object has been added to the
containing L<IO::Async::Loop> object.
=head2 on_exit => CODE
CODE reference for the C<on_exit> event.
Once the C<on_exit> continuation has been invoked, the C<IO::Async::PID>
object is removed from the containing L<IO::Async::Loop> object.
=cut
sub configure
{
my $self = shift;
my %params = @_;
( run in 1.010 second using v1.01-cache-2.11-cpan-39bf76dae61 )