AnyEvent-Process
view release on metacpan or search on metacpan
lib/AnyEvent/Process.pm view on Meta::CPAN
my $nop = sub {};
sub _yield {
my $cv_yield = AE::cv;
AE::postpone { $cv_yield->send };
$cv_yield->recv;
}
# Create a callback factory. This is needed to execute on_completion after all
# other callbacks.
sub _create_callback_factory {
my $on_completion = shift // $nop;
my $counter = 0;
my @on_completion_args;
my $factory = sub {
my $func = shift // $nop;
$counter++;
return sub {
lib/AnyEvent/Process.pm view on Meta::CPAN
my $hdl = AnyEvent::Handle->new(fh => $handle->[0], @hdl_args);
foreach my $call (@hdl_calls) {
no strict 'refs';
my $method = $call->[0];
AE::log trace => "Calling handle method $method(" . join(', ', @{$call->[1]}) . ')';
$hdl->$method(@{$call->[1]});
}
$job->_add_handle($hdl);
}
# Create callbacks
my $completion_cb = sub {
$job->_remove_timers();
AE::log info => "Process $job->{pid} finished with code $_[1].";
$set_on_completion_args->($job, $_[1]);
};
$job->_add_cb(AE::child $pid, $callback_factory->($completion_cb));
$self->{job} = $job;
# Create watchdog and kill timers
lib/AnyEvent/Process.pm view on Meta::CPAN
=item args (optional)
Arguments past to a code reference specified as code argument when it is called.
=item on_completion (optional)
Callback, which is executed when the process finishes. It receives
AnyEvent::Process::Job instance as the first argument and exit code as the
second argument.
It is called after all AnyEvent::Handle callbacks specified in the fh_table.
=item watchdog_interval (in seconds, optional)
How often a watchdog shall be called. If undefined or set to 0, the watchdog
functionality is disabled.
=item on_watchdog (optional)
Watchdog callback, receives AnyEvent::Process::Job instance as its argument.
If it returns false value, the watched process is killed (see on_kill).
( run in 0.486 second using v1.01-cache-2.11-cpan-9b1e4054eb1 )