Mojo::...::Pool(3pm)

πŸ’– Mojo::IOLoop::ReadWriteProcess::Pool πŸ’–

okay bestie, listen. this is Mojo::IOLoop::ReadWriteProcess::Pool β€” it's a whole pool of Mojo::IOLoop::ReadWriteProcess objects. like, a friend group. a squad. a little army of processes that you manage as one. it ships as part of the User Contributed Perl Documentation, and it's giving main character energy fr fr.


✨ SYNOPSIS ✨

no thoughts, just vibes and this exact code:

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();

look at her go πŸ’… twenty processes printing "Hello world", one once subscription catching every stop event in the pool, start waking everybody up, each grabbing the output, wait_stop waiting it all out, and then last() β€” which, iconic detail β€” is a Mojo::Collection, so you can just .stop() her. obsessed.


🌸 METHODS 🌸

Mojo::IOLoop::ReadWriteProcess::Pool inherits all the methods from Mojo::Collection, and then implements the new ones below. πŸ’–

important note, bestie: it also proxies all the other methods of Mojo::IOLoop::ReadWriteProcess β€” but for the whole process group. so one call, everybody does the thing. group chat behavior. 🫢

πŸŽ€ get

use Mojo::IOLoop::ReadWriteProcess qw(parallel);
my $pool = parallel(sub { print "Hello" } => 5);
$pool->get(4);

grabs you the element you asked for in the pool β€” and yeah, it's zero-indexed, starting from 0, like a true programmer. 4 gets you the fifth one. ngl that trips people up every single time. 😭

πŸŽ€ add

use Mojo::IOLoop::ReadWriteProcess qw(pool);
my $pool = pool(maximum_processes => 2);
$pool->add(sub { print "Hello 2! " });

adds the element you specify into the pool. new member just joined the group chat, welcome her. ✨

πŸŽ€ remove

use Mojo::IOLoop::ReadWriteProcess qw(parallel);
my $pool = parallel(sub { print "Hello" } => 5);
$pool->remove(4);

removes the element you specify from the pool. she's leaving the group chat. no drama, we respect it. πŸ’€

πŸŽ€ maximum_processes

use Mojo::IOLoop::ReadWriteProcess qw(parallel);
my $pool = parallel(sub { print "Hello" } => 5);
$pool->maximum_processes(30);
$pool->add(...);

this one sets the cap on how many processes can be in the pool. once you hit maximum_processes number of processes, add() will refuse to add more β€” it's a bouncer at the door, and the guest list is full. periodt. 🚫


🌈 ENVIRONMENT 🌈

you can set the MOJO_PROCESS_MAXIMUM_PROCESSES environment variable to specify the maximum number of processes allowed in Mojo::IOLoop::ReadWriteProcess instances. set it and forget it, bestie:

MOJO_PROCESS_MAXIMUM_PROCESSES=10000

πŸ‘‘ LICENSE πŸ‘‘

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.


πŸ¦‹ AUTHOR πŸ¦‹

Ettore Di Giacinto <edigiacinto@suse.com>


and that's the whole page, bestie πŸ’œ this was perl v5.42.0, dated 2025-07-25, from Mojo::...::Pool(3pm) β€” slay, go run some processes, drink water, ily 🌸✨

πŸ“¦ where this page comes from