GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages
Parallel::Async::Task(3) User Contributed Perl Documentation Parallel::Async::Task(3)

Parallel::Async::Task - task class for Parallel::Async.

$task = Parallel::Async::Task->new(\%args)
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.

my @result = $task->recv(@args)
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
    
my $watcher = $task->as_anyevent_child(@args)
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);
    
my $pid = $task->run(@args)
Execute task on child process.

    # create new task
    my $task = async {
        my ($url) = @_;
        post($url);
    };

    my $pid = $task->run($url);
    wait;
    
my $pid = $task->daemonize(@args)
Execute task on daemonized process.

    # create new task
    my $task = async {
        my ($url) = @_;
        post($url);
    };

    my $pid = $task->daemonize($url);
    
my $chain = $task->join($task1, ...);
Join multiple tasks. Can be execute tasks in parallel by chained task. See also Parallel::Async::Chain for more usage.
$task->reset;
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
    
$task->clone;
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>
2022-04-09 perl v5.32.1

Search for    or go to Top of page |  Section 3 |  Main Index

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with ManDoc.