The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

Parallel::Pipes::App - friendly interface for Parallel::Pipes

SYNOPSIS

use Parallel::Pipes::App;

my @result = Parallel::Pipes::App->map(
  num => 3,
  work => sub { my $task = shift; $task * 2 },
  tasks => [1, 2, 3, 4, 5],
);
# @result is ( 2, 4, 6, 8, 10 )

DESCRIPTION

Parallel::Pipes::App provides friendly interfaces for Parallel::Pipes.

METHODS

Parallel::Pipes::App provides 2 class method:

map

my @result = Parallel::Pipes::App->map(
  num => $num,
  work => $work,
  tasks => \@task,
);

Process @task by $work in $num pre-forked child processes, and get @result. This is almost the same as

my @result = map { $work->($_) } @task;

except that $work is executed in a child process, not in the current process.

run

Parallel::Pipes::App->run(
  num => $num,
  work => $work,
  tasks => \@task,
  before_work => $before_work,
  after_work => $after_work,
);

run is a more generic form of map. In fact, we can write map by using run:

my @result;
Parallel::Pipes::App->run(
  num => $num,
  work => $work,
  tasks => \@task,
  before_work => sub {},
  after_work => sub { push @result, $_[0] },
);

AUTHOR

Shoichi Kaji <skaji@cpan.org>

COPYRIGHT AND LICENSE

Copyright 2016 Shoichi Kaji <skaji@cpan.org>

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.