# Copyright (C) 2015-2019 Joelle Maslak # All Rights Reserved - See License # package Parallel::WorkUnit::Procedural; $Parallel::WorkUnit::Procedural::VERSION = '2.232180'; use v5.8; # ABSTRACT: Provide procedural paradigm forking with ability to pass back data use strict; use warnings; use autodie; require Exporter; our @ISA = qw(Exporter); our @EXPORT_OK = qw( async asyncs proc_count proc_wait queue start waitall waitone WorkUnit ); our %EXPORT_TAGS = ( all => [@EXPORT_OK] ); use Carp; use Parallel::WorkUnit; use namespace::autoclean; my $wu = Parallel::WorkUnit->new(); sub WorkUnit() { $wu = Parallel::WorkUnit->new() if !defined($wu); return $wu; } sub async(&;&) { return WorkUnit->async(@_) } sub asyncs { return WorkUnit->asyncs(@_) } sub waitall() { return WorkUnit->waitall() } sub waitone { return WorkUnit->waitone(@_) } sub proc_wait { return WorkUnit->wait(@_) } sub proc_count() { return WorkUnit->count() } sub queue { return WorkUnit->queue(@_) } sub start(&) { return WorkUnit->start(@_) } 1; __END__ =pod =encoding UTF-8 =head1 NAME Parallel::WorkUnit::Procedural - Provide procedural paradigm forking with ability to pass back data =head1 VERSION version 2.232180 =head1 SYNOPSIS # # Procedural Interface # use Parallel::WorkUnit::Procedural qw(:all); # Export all symbols async sub { ... }, \&callback; waitall; # # Limiting Maximum Parallelization # WorkUnit->max_children(5); queue sub { ... }, \&callback; waitall; # # Ordered Responses # async sub { ... }; @results = waitall; # # Spawning off X number of workers # (Ordered Response paradigm shown with 10 children) # asyncs( 10, sub { ... } ); @results = waitall; # # AnyEvent Interface # use AnyEvent; WorkUnit->use_anyevent(1); async sub { ... }, \&callback; waitall; # Not strictly necessary # # Just spawn something into another process, don't capture return # values, don't allow waiting on process, etc. # start { ... }; =head1 DESCRIPTION This provides a simple procedural instance to L where it is not important to modify attributes of the global Parallel::WorkUnit singleton used by this module. While the underlying singleton is exposed (via the C subroutine), it is highly recommended that users not use this directly, as unexpected interactions may occur (it is a global singleton, after all!). Please read the documentation on L for detailed information about this module. This module was added to the Parallel-WorkUnit distribution in 1.191810. =head1 FUNCTIONS =head2 WorkUnit Returns the singleton Parallel::WorkUnit used by this module. This can be used to access attributes such as C and C. =head2 async { ... }, \&callback async sub { return 1 } \&callback; # To get back results in "ordered" return mode async sub { return 1 }; @results = waitall; This executes Casync()> =head2 asyncs( $children, sub { ... }, \&callback ) Executes Casyncs() } =head2 waitall Executes Cwaitall()> =head2 waitone Executes Cwaitone()> =head2 proc_wait($pid) Executes Cwait()> =head2 proc_count() Executes Ccount()> =head2 queue sub { ... }, \&callback Executes Cqueue()> =head2 start { ... }; This executes Cstart()> =head1 AUTHOR Joelle Maslak =head1 COPYRIGHT AND LICENSE This software is copyright (c) 2015-2023 by Joelle Maslak. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. =cut