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