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


Manual Reference Pages  -  PARALLEL::ASYNC::TASK (3)

.ds Aq ’

NAME

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

CONTENTS

METHODS

$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:
o 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);



AUTHOR

karupanerura <karupa@cpan.org>
Search for    or go to Top of page |  Section 3 |  Main Index


perl v5.20.3 PARALLEL::ASYNC::TASK (3) 2016-03-18

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