Parallel::Async::Task - task class for Parallel::Async.
Creates a new Parallel::Async::Task instance.
use Parallel::Async::Task; # create new task my $task = Parallel::Async::Task->new(code => sub { my $result = ...; ## do some task return $result; });
this code is same as
use Parallel::Async; # create new task my $task = async { my $result = ...; ## do some task return $result; };
Arguments can be:
code
CodeRef to run on child process. This CodeRef can get arguments from recv or as_anyevent_child or run method arguments.
recv
as_anyevent_child
run
Execute task on child process and wait for receive return value.
# create new task my $task = async { my ($x, $y) = @_; return $x + $y; }; my $res = $task->recv(10, 20); say $res; # 30
Execute task on child process and receive return value with AnyEvent->child. This feature required AnyEvent.
# create new task my $task = async { my ($x, $y) = @_; return $x + $y; }; my $watcher; $watcher = $task->as_anyevent_child(sub { my ($pid, $status, $res) = @_; say $res; ## 30 undef $watcher; }, 10, 20);
Execute task on child process.
# create new task my $task = async { my ($url) = @_; post($url); }; my $pid = $task->run($url); wait;
Execute task on daemonized process.
# create new task my $task = async { my ($url) = @_; post($url); }; my $pid = $task->daemonize($url);
Join multiple tasks. Can be execute tasks in parallel by chained task. See also Parallel::Async::Chain for more usage.
Reset the execution status of the task. This feature is useful when you want to re-execute the same task.
# create new task my $task = async { my ($x, $y) = @_; return $x + $y; }; my $res = $task->recv(10, 20); say $res; # 30 $res = $task->reset->recv(10, 30); say $res; # 40
Clone and reset the execution status of the task. This feature is useful when you want to execute same tasks in parallel.
# create new task my $task = async { my ($x, $y) = @_; return $x + $y; }; my @res = $task->join(map { $task->clone } 1..9)->recv(10, 30);
karupanerura <karupa@cpan.org>
To install Parallel::Async, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Parallel::Async
CPAN shell
perl -MCPAN -e shell install Parallel::Async
For more information on module installation, please visit the detailed CPAN module installation guide.