Mojo::...::Queue(3pm)

πŸ’– Mojo::...::Queue β€” the whole vibe πŸ’–

okay bestie, sit down, hydrate, because this is literally the manual page for Mojo::IOLoop::ReadWriteProcess::Queue (you'll see it filed under the short name Mojo::...::Queue(3pm), we keep it cute around here) β€” and it's exactly what it sounds like: it's a queue for Mojo::IOLoop::ReadWriteProcess objects. a whole little line-up of processes waiting their turn. it's giving ✨organized chaos✨ and we're obsessed.


✨ NAME ✨

Mojo::IOLoop::ReadWriteProcess::Queue β€” a Queue for Mojo::IOLoop::ReadWriteProcess objects. no notes, that's the whole thing, periodt. πŸ’…


🌸 SYNOPSIS 🌸

here's the whole main-character moment, verbatim, no cap:

use Mojo::IOLoop::ReadWriteProcess qw(queue process);
my $n_proc = 20;
my $fired;

my $q = queue;

$q->pool->maximum_processes(2); # Max 2 processes in parallel
$q->queue->maximum_processes(10); # Max queue is 10

$q->add( process sub { return 42 } ) for 1..7;

# Subscribe to all "stop" events in the pool
$q->once(stop => sub { $fired++; });

# Consume the queue
$q->consume();

my $all = $q->done; # All processes, Mojo::Collection of Mojo::IOLoop::ReadWriteProcess

# Set your own running pool
$q->pool(parallel sub { return 42 } => 5);

# Set your own queue
$q->queue(parallel sub { return 42 } => 20);

$q->consume();

like... she builds a queue, caps the pool at 2, caps the queue at 10, yeets 7 processes in, subscribes to every "stop" event in the pool, consumes the whole thing, and collects the finished processes as a Mojo::Collection of Mojo::IOLoop::ReadWriteProcess. iconic behaviour honestly 🫢


πŸ¦‹ METHODS πŸ¦‹

Mojo::IOLoop::ReadWriteProcess::Queue inherits all the methods from Mojo::Base and then implements these new ones below. πŸ’–

quick heads-up bestie: it also proxies all the other methods of Mojo::IOLoop::ReadWriteProcess for the whole process group. so the whole squad answers to the same calls. iykyk.

πŸŽ€ add

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

Adds the process to the queue. that's it. that's the method. drop it in, let it wait its turn. ✨


πŸ“ consume

use Mojo::IOLoop::ReadWriteProcess qw(queue);
my $q = queue();
$q->add(sub { print "Hello 2! " });
$q->add(process sub { print "Hello 2! " });
$q->consume; # executes and exhaust the processes

Starts the processes and empties the queue. no leftovers, no crumbs, ate and left no plate. πŸ”₯

important note, bestie: maximum_processes can be set both on the pool (that's the number of processes to be run in parallel) and on the queue (which gets exhausted during the consume() phase). two different knobs, two different jobs, don't mix them up.
$q->pool->maximum_processes(2); # Max 2 processes in parallel
$q->queue->maximum_processes(10); # Max queue is 10

🧚 exhausted

use Mojo::IOLoop::ReadWriteProcess qw(queue);
my $q = queue();
$q->add(sub { print "Hello 2! " });
$q->add(process sub { print "Hello 2! " });
$q->consume; # executes and exhaust the processes
$q->exhausted; # 1

Returns 1 if the queue is exhausted. that's the vibe check: is she empty? yes? 1. πŸŽ€


🌈 ENVIRONMENT 🌈

you can set the MOJO_PROCESS_MAXIMUM_PROCESSES environment variable to specify the the maximum number of processes allowed in the pool and the queue β€” which are Mojo::IOLoop::ReadWriteProcess::Pool instances. (yes, the "the the" is in the original, we're preserving it like a museum artifact, no cap πŸ’€)

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.

so like... free software, same terms as Perl itself, go wild but be normal about it. πŸ’œ


⭐ AUTHOR ⭐

Ettore Di Giacinto <edigiacinto@suse.com>


and that's the whole page bestie, no crumbs left, we ATE πŸ¦‹βœ¨

this little masterpiece was served to you by perl v5.42.0, dated 2025-07-25, and filed under Mojo::...::Queue(3pm) β€” mwah, take care of her, she's iconic πŸ’…πŸ’–

πŸ“¦ where this page comes from