Mojo::IOLoop::ReadWriteProcess::Pool(3pm) | User Contributed Perl Documentation | Mojo::IOLoop::ReadWriteProcess::Pool(3pm) |
Mojo::IOLoop::ReadWriteProcess::Pool - Pool of Mojo::IOLoop::ReadWriteProcess objects.
use Mojo::IOLoop::ReadWriteProcess qw(parallel); my $n_proc = 20; my $fired; my $p = parallel sub { print "Hello world\n"; } => $n_proc; # Subscribe to all "stop" events in the pool $p->once(stop => sub { $fired++; }); # Start all processes belonging to the pool $p->start(); # Receive the process output $p->each(sub { my $p = shift; $p->getline(); }); $p->wait_stop; # Get the last one! (it's a Mojo::Collection!) $p->last()->stop();
Mojo::IOLoop::ReadWriteProcess::Pool inherits all methods from Mojo::Collection and implements the following new ones. Note: It proxies all the other methods of Mojo::IOLoop::ReadWriteProcess for the whole process group.
use Mojo::IOLoop::ReadWriteProcess qw(parallel); my $pool = parallel(sub { print "Hello" } => 5); $pool->get(4);
Get the element specified in the pool (starting from 0).
use Mojo::IOLoop::ReadWriteProcess qw(pool); my $pool = pool(maximum_processes => 2); $pool->add(sub { print "Hello 2! " });
Add the element specified in the pool.
use Mojo::IOLoop::ReadWriteProcess qw(parallel); my $pool = parallel(sub { print "Hello" } => 5); $pool->remove(4);
Remove the element specified in the pool.
use Mojo::IOLoop::ReadWriteProcess qw(parallel); my $pool = parallel(sub { print "Hello" } => 5); $pool->maximum_processes(30); $pool->add(...);
Prevent from adding processes to the pool. If we reach "maximum_processes" number of processes, "add()" will refuse to add more to the pool.
You can set the MOJO_PROCESS_MAXIMUM_PROCESSES environment variable to specify the the maximum number of processes allowed in Mojo::IOLoop::ReadWriteProcess instances.
MOJO_PROCESS_MAXIMUM_PROCESSES=10000
Copyright (C) Ettore Di Giacinto.
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
Ettore Di Giacinto <edigiacinto@suse.com>
2022-12-30 | perl v5.36.0 |