dluxhu / perl-parallel-forkmanager

Parallel::ForkManager
20 stars 11 forks source link

Why start_child() doesn't take additional args for cb? #25

Open 0x62ash opened 5 years ago

0x62ash commented 5 years ago

Proposal start_child [ $process_identifier, @args, ] \&callback

Implementation (not tested)

sub start_child {
    my $self = shift;
    my $sub = pop;
    my $identification = shift;

    $self->start( $identification ) # in the parent
            # ... or the child
        or $self->finish( 0, $sub->(@_) );
}
yanick commented 5 years ago

The reason there is no way to pass arguments as of now is mostly because

$pm->start_child( 'foo', 1, 2, 3, \&callback );

can be written as

$pm->start_child( 'foo', sub { callback(1,2,3) }  );

But I'm not opposed at all to that bit of syntactic sugar. Would you like to do us the honors and whip up a PR? :-)