BGS - Background execution of subroutines in child processes.
use BGS; # $BGS::limit = 0; my @foo; foreach my $i (1 .. 2) { bgs_call { # child process return "Start $i"; } bgs_back { # callback subroutine my $r = shift; push @foo, "End $i. Result: '$r'.\n"; }; } bgs_wait(); print foreach @foo;
The module was created when need to receive information from dozens of database servers in the shortest time appeared.
Child process is created for each subroutine, that is prescribed with bgs_call, and it executes within this child process.
The subroutine must return either a scalar or a reference!
The answer of the subroutine passes to the callback subroutine as an argument. If a child process ended without bgs_call value returning, than bgs_back subprogram is called without argument.
bgs_call return vpid (virtual pid) of child process.
The callback subroutine is described in bgs_back block.
The answer of bgs_call subroutine passes to bgs_back subroutine as an argument.
Call of bgs_wait() reduces to child processes answers wait and callback subroutines execution.
Call bgs_wait($vpid) to wait specific process.
kill all or specific child processes.
Call bgs_break($vpid) to kill specific process.
Set $BGS::limit to limit child processes count. Default is 0 (unlimited).
Nick Kostyria
Copyright (C) 2011 by Nick Kostyria
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.8 or, at your option, any later version of Perl 5 you may have available.
To install BGS, copy and paste the appropriate command in to your terminal.
cpanm
cpanm BGS
CPAN shell
perl -MCPAN -e shell install BGS
For more information on module installation, please visit the detailed CPAN module installation guide.