Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: parallel functions

by marioroy (Scribe)
on Nov 25, 2012 at 06:26 UTC ( #1005465=note: print w/ replies, xml ) Need Help??


in reply to parallel functions

A new parallel module was recently added to CPAN called MCE. This is how one could run 2 functions in parallel using MCE.

#!/usr/bin/perl use 5.014; use MCE; my $mce = MCE->new( max_workers => 2, user_func => sub { my $self = shift; if ($self->wid == 1) { test1(); } else { test2(); } } ); $mce->run(); sub test1 { sleep 3; say "in test1"; } sub test2 { sleep 2; say "in test2"; }

Output

in test2 in test1


Comment on Re: parallel functions
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1005465]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (7)
As of 2015-07-04 16:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (60 votes), past polls