Fsdb::Support::Freds - an abstraction over fork and/or ithreads
use Fsdb::Support::Freds; my $fred = new Fsdb::Support::Freds('new thread to do foo'); # or my $fred = new Fsdb::Support::Freds('demo_fred', sub { child_stuff(); exit 0; }, sub { say "child is done\n"; } ); $fred->join(); # or $fred->detach();
This package provides an abstraction over fork that is something like Perl's ithreads. Our goal is to abstract process creation and collection, but none of the shared data like ithreads.
(Why "Freds"? Because it's fork-based thread-like things, and "Tasks" seems too generic.)
$fsdb = new Fsdb::Support::Freds($description, $child_sub, $ending_sub);
For a process, labeling it with optional $DESCRIPTION then running optional $CHILD_SUB in the subprocess, then running optional $ENDING_SUB in the parent process when it exits.
$ENDING_SUB is passed three arguments, the fred, the shell exit code (typically 0 for success or non-zero for failure), and the wait return code (the shell exit code shifted, plus signal number).
It is the job of the $CHILD_SUB to exit if it wants. Otherwise this function returns to the caller.
$fred->is_child();
Are we the child? Returns undef if parent.
$info = $fred->info();
Return a string description of the Fred.
$fred->error();
Non-zero if in error state.
$fred->exit_code($full);
Exit code of a termintated fred. With $FULL, turn the full version (including errors). Typically "0" means success.
$fred->_post_join();
Internal cleanup after $FRED is terminated.
$fred->join();
Join a fred (wait for the process to finish). Returns -1 on error (Including if not in the parent.)
my $fred = Fsdb::Support::Freds::join_any($BLOCK);
Join on some pending fred, without blocking (default) or blocking (if $BLOCK) is set. Returns -1 on error. Returns 0 if something is running but not finished.
Returns the $FRED that ends.
my $fred = Fsdb::Support::Freds::join_all();
Reap all pending threads.
Detect any non-reaped processes.
To install Fsdb, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Fsdb
CPAN shell
perl -MCPAN -e shell install Fsdb
For more information on module installation, please visit the detailed CPAN module installation guide.