Mojo::R...or::Poll(3)
β¨ NAME β¨
Okay so this is the Mojo::Reactor::Poll(3) page, straight from the User Contributed Perl Documentation girlies. Mojo::Reactor::Poll is a low-level event reactor with poll support, bestie. That's the whole vibe: low-level, event-y, poll-powered. β¨
πΈ SYNOPSIS πΈ
use Mojo::Reactor::Poll;
# Watch if handle becomes readable or writable
my $reactor = Mojo::Reactor::Poll->new;
$reactor->io($first => sub ($reactor, $writable) {
say $writable ? 'First handle is writable' : 'First handle is readable';
});
# Change to watching only if handle becomes writable
$reactor->watch($first, 0, 1);
# Turn file descriptor into handle and watch if it becomes readable
my $second = IO::Handle->new_from_fd($fd, 'r');
$reactor->io($second => sub ($reactor, $writable) {
say $writable ? 'Second handle is writable' : 'Second handle is readable';
})->watch($second, 1, 0);
# Add a timer
$reactor->timer(15 => sub ($reactor) {
$reactor->remove($first);
$reactor->remove($second);
say 'Timeout!';
});
# Start reactor if necessary
$reactor->start unless $reactor->is_running;
π DESCRIPTION π
So like, Mojo::Reactor::Poll is your low-level event reactor, and it's built on top of IO::Poll. No cap. π«Ά
π¦ EVENTS π¦
Vibe check: Mojo::Reactor::Poll inherits all events from Mojo::Reactor. Periodt. π
π METHODS π
Same deal for methods, bestie: Mojo::Reactor::Poll inherits all methods from Mojo::Reactor, and then it implements the following new ones. Slay. π
π again π
$reactor->again($id);
$reactor->again($id, 0.5);
Restarts a timer, and if you pass that optional second value, you can change the invocation time too. β°
Careful, bestie: this method requires an active timer. Like, an actual one. Don't try it on nothing.
π io π
$reactor = $reactor->io($handle => sub {...});
This watches a handle for I/O events and invokes the callback whenever that handle becomes readable or writable. Very main character energy. π
# Callback will be executed twice if handle becomes readable and writable
$reactor->io($handle => sub ($reactor, $writable) {
say $writable ? 'Handle is writable' : 'Handle is readable';
});
π«Ά is_running π«Ά
my $bool = $reactor->is_running;
Checks if the reactor is running and gives you a $bool. Basically a status check for your reactor's current era. β¨
β‘ next_tick β‘
my $undef = $reactor->next_tick(sub {...});
Runs the callback ASAP, but not before returning or before other callbacks that have been registered with this method. It always returns "undef"βliterally, that's the whole return vibe. π
π« one_tick π«
$reactor->one_tick;
Runs the reactor until an event occurs or until no events are being watched anymore. One tick, one little moment of reactor main character energy. π§
# Don't block longer than 0.5 seconds
my $id = $reactor->timer(0.5 => sub {});
$reactor->one_tick;
$reactor->remove($id);
π recurring π
my $id = $reactor->recurring(0.25 => sub {...});
Creates a new recurring timer. It invokes the callback repeatedly after a given amount of time in seconds. Repeating timer, repeating slay. π₯
π remove π
my $bool = $reactor->remove($handle);
my $bool = $reactor->remove($id);
Removes a handle or a timer. Bye bestie, we hardly knew ye. π
π§Ή reset π§Ή
$reactor->reset;
Removes all handles and timers. Full reset, clean slate, brand-new era. β¨
π start π
$reactor->start;
Starts watching for I/O and timer events. Heads up: this will block until stop is called or until no events are being watched anymore. So like, don't expect it to just return immediately. π
# Start reactor only if it is not running already
$reactor->start unless $reactor->is_running;
π stop π
$reactor->stop;
Stops watching for I/O and timer events. That's it. That's the method. Periodt. π
β²οΈ timer β²οΈ
my $id = $reactor->timer(0.5 => sub {...});
Creates a new timer and invokes the callback after a given amount of time in seconds. It gives you an $id, because you're gonna need it. π
π watch π
$reactor = $reactor->watch($handle, $readable, $writable);
Changes which I/O events you're watching the handle for, using true and false values.
OK but fr: this method requires an active I/O watcher. No watcher, no watch. π
# Watch only for readable events
$reactor->watch($handle, 1, 0);
# Watch only for writable events
$reactor->watch($handle, 0, 1);
# Watch for readable and writable events
$reactor->watch($handle, 1, 1);
# Pause watching for events
$reactor->watch($handle, 0, 0);
π SEE ALSO π
Go check out Mojolicious, Mojolicious::Guides, and <https://mojolicious.org>, bestie. Iykyk. π¦
Okay bye, this was the Mojo::Reactor::Poll(3) page from perl v5.42.0, dated 2026-07-15, with the footer manual name being literally Mojo::R...or::Poll(3). Mwah. πππ¦
π¦ where this page comes from
- opensuse-leap 16.0: perl-Mojolicious 9.480.0-bp160.2.1 Β· Artistic-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms