NAME

WWW::Noss::Forker - noss fork manager

SYNOPSIS

use WWW::Noss::Forker;

my $f = WWW::Noss::Forker->new(10);

FORKLOOP: for my $dl (@downloads) {
    $f->start and next FORKLOOP;
    download($dl);
    $f->finish;
}

$f->wait_all_children;

DESCRIPTION

WWW::Noss::Forker is a module for managing multiple simultaneous forks easily. It is designed to be a lightweight counterpart to Parallel::ForkManager. This is a private module, please consult the noss manual for user documentation.

METHODS

$forker = WWW::Noss::Forker->new($forks)

Create a WWW::Noss::Forker object. $forks is the maximum number of forks to perform.

$forker->run_on_finish($subref)

Run $subref upon the exit of a fork. $subref will be given the following arguments when called:

0   $pid   PID of terminating process
1   $exit  Exit status of terminating process
2   $data  Data passed to $forker->finish(), undef if not present
$kid = $forker->wait_next()

Waits for next child to finish running and returns its PID.

$pid = $forker->start()

Starts executing next fork. If the maximum number of forks has been reached, $forker will wait until another fork has been completed.

Returns the PID of the forked process to the parent, and 0 to the fork.

$forker->finish([ $code, [ $data ] ])

Finish and exit the current fork. $code is the code to exit the fork with, defaults to 0. $data is a reference to data to pass to the subroutine set in run_on_finish().

$waited = $forker->wait_all_children()

Waits for all children to complete. Returns the number of children completed.

AUTHOR

Written by Samuel Young, <samyoung12788@gmail.com>.

This project's source can be found on its Codeberg page. Comments and pull requests are welcome!

COPYRIGHT

Copyright (C) 2026 Samuel Young

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

SEE ALSO

Parallel::ForkManager, noss